import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}


//Author KNIGHT0X300 

import java.util.Scanner;
import java.util.TreeSet;




public class Main {
    
    public static void main(String[] args) {
       Scanner s=new Scanner(System.in);
     TreeSet<Integer> ts=new TreeSet<Integer>();
       int[] A1=new int[8];
      A1[0]=1; A1[1]=10; A1[2]=100; A1[3]=1000; A1[4]=10000; A1[5]=100000; A1[6]=1000000; A1[7]=10000000;
       int t=s.nextInt();
     long time = System.nanoTime();  
       for(int i=0;i<t;i++)
       {  int tot=0;
           int A=s.nextInt();
           int B=s.nextInt();
               for(int j=B;j>A;j--)
         {  int y=j ;
         ts.clear();
            int sz= (int)Math.floor(Math.log10(j));
             
         for(int k=1;k<sz+1;k++)
         {  
             int p=j%(int)A1[k];
             y= (int) (Math.floor(j/A1[k])+p*(int)A1[sz+1-k]);
          
         
             if((y<j)&&(y>=A)){
                 if(!ts.contains(y))
                  tot++;ts.add(y);}
        
             }
         
         }
         
         
         
         
           
           
           
           
           
           
        System.out.println("Case #"+(i+1)+": "+tot);
                      
          
       }
       
 System.out.println("Finished in: " + (System.nanoTime() - time) / Math.pow(10, 6) + "ms");
    }
}
