import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2

public class C {

	private static String process(Scanner in) {
		int A = in.nextInt();
		int B = in.nextInt();
		int res = 0;
		int len = Integer.toString(A).length();
		for(int n = A; n < B; n++) {
			String str = Integer.toString(n);
			TreeSet<Integer> set = new TreeSet<Integer>();
			for(int i = 1; i < len; i++) {
				int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
				if ( m > n && m <= B && ! set.contains(m) ) {
					set.add(m);
					res++;
				}
			}
		}
		return Integer.toString(res);
	}

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in.available() > 0 ? System.in : 
			new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
		int T = in.nextInt();
		for(int i = 1; i <= T; i++) 
			System.out.format("Case #%d: %s\n", i, process(in));
	}
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package googlecodejam_recyclingnumbers;

import java.io.*;

/**
 *
 * @author Ulyss
 */
public class GoogleCodeJam_RecyclingNumbers {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        // TODO code application logic here
        
        
        BufferedReader br = new BufferedReader(new FileReader("C-small.in"));
        
        PrintWriter pw = new PrintWriter("C-small.out");
        
        int T = Integer.parseInt(br.readLine());
        
        for(int i = 0; i < T; i++){
        
            int total = 0;
            
            String line = br.readLine();
            
            String[] numbers = line.split(" ");
            
            int A = Integer.parseInt(numbers[0]);
            int B = Integer.parseInt(numbers[1]);
            
            System.out.println(A + " : " + B);
            
            for(int lowIndex = A; lowIndex < B; lowIndex++){
                
                for(int highIndex = lowIndex+1; highIndex <= B; highIndex++){
                    
                    if( isRecycled(lowIndex, highIndex) ){
                        
                        System.out.println(" Yes!!! " + lowIndex + " - " + highIndex);
                        total++;
                    }
                }
            }
            
            pw.print("Case #" + (i+1) + ": " + total);
            if( i < T-1 ){
                
                pw.println();
            }
        }
        
        br.close();
        pw.close();
    }
    
    public static boolean isRecycled(int n, int m){
        
        if( n < 10 ){
            
            return false;
        }
        if( n < 100 ){
            
            if( n % 10 == m / 10 && n / 10 == m % 10 ){
                
                return true;
            }
            else{
                
                return false;
            }
        }
        
        if( n < 1000 ){
            
            String nLine = String.valueOf(n);
            String mLine = String.valueOf(m);
            
            if( ( nLine.charAt(2) == mLine.charAt(0) && nLine.charAt(0) == mLine.charAt(1) && nLine.charAt(1) == mLine.charAt(2) ) ||
                ( nLine.charAt(0) == mLine.charAt(2) && nLine.charAt(1) == mLine.charAt(0) && nLine.charAt(2) == mLine.charAt(1) ) ){
                
                return true;
            }
        }
        
        return false;
    }
    
    
}
