package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}



//Author KNIGHT0X300 

import java.util.Scanner;




public class Main {
    
    public static void main(String[] args) {
       Scanner s=new Scanner(System.in);
       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();
             int sz= (int)Math.log10(B);//digits-1
           //  System.out.println(sz);
         for(int j=B;j>A;j--)
         {  int y=j ;
           
             
         for(int k=1;k<sz+1;k++)
         {  
             int p=j%(int)Math.pow(10, k);
     //  if((p==0))
            //   continue;
         y= (int) (Math.floor(j/Math.pow(10, k))+p*(int)Math.pow(10, sz+1-k));
          
            // System.out.println(y);
//          if((p==0))//&&(p==0))
//          {  System.out.println("fahnsfjqnfjqfdjqn  "+y);}
             if((y<j)&&(y>=A)){tot++;
           System.out.println(j+" "+y);
//             if(j-y<=0)  
//                 System.out.println("wfjhdddddhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
//               if((p==0))//&&(p==0))
//                 System.out.println("fahnsfjqnfjqfdjqn");
             }
         
         }
         
         
         
         }
           
           
           
           
           
           
        System.out.println("Case #"+(i+1)+": "+tot);
                      
          
       }
       
 System.out.println("Finished in: " + (System.nanoTime() - time) / Math.pow(10, 6) + "ms");
    }
}
