import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

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

package a_q_gcj2012;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 *
 * @author Nekomi
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {

        String buf[] = new String[2000001];

        for(int i= 0;i< 20001;++i) {
            int nt[] = new int[10];
            String st = String.format("%d", i);

            for(char s: st.toCharArray()) {
                nt[s-'0'] ++;
            }

            int str_len = st.length();
            char c[] = new char[st.length()];

            int p= 0;
            for(int j=0; j<10;j++) {
                for(int k=0;k<nt[j];k++) {
                    c[p] = (char) (j +'0');
                    p++;
                }
            }
            buf[i] = new String(c);

            //System.out.print(i + ":" + buf[i]+"\r\n");

        }

        // TODO code application logic here
        File file = new File("c:\\work\\c.in");
        File filew = new File("c:\\work\\outC.txt");

        FileReader rr = new FileReader(file);
	BufferedReader r = new BufferedReader(rr);

        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(filew)));

        String line;
        int lineNo = 1;

        line = r.readLine();
        while ((line = r.readLine()) != null) {
             String[] splited = line.split(" ");

            int A = Integer.valueOf(splited[0]);
            int B = Integer.valueOf(splited[1]);

            int result = 0;

            for(int n=A;n<B;n++)
                for(int m=n+1;m<=B;m++)
                    if (buf[n].equals(buf[m])) {
                        String sn = String.valueOf(n);
                        String sm = String.valueOf(m);
                        
                        int len = sn.length();
                        for(int q=1;q<len;q++) {
                            String sm1 = sm.substring(0,q);
                            String sm2 = sm.substring(q, len);

                            if ((sm2+sm1).equals(sn)) {
                                result++;
                                //System.out.print("n:"+n +" m:"+m + "\n\r");
                                break;
                            }
                        }
                    }

            String strAns = "Case #" + Integer.toString(lineNo)
                    + ": " + String.valueOf(result)+"\n\r";

            System.out.print(strAns);

            lineNo ++;

            pw.println(strAns);
        }
        r.close();
        pw.close();
    }

}
