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 c;
 

import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

/**
 *
 * @author Leo
 */
public class C {
  public static void main(String[] args) throws FileNotFoundException, IOException {
       
  new C().run();
  }
    
    String inputFile = "txt.in";
     Scanner in;
	
     public void run() throws FileNotFoundException, IOException{
        in = new Scanner(new FileReader(inputFile));
		
        int cases = in.nextInt();
      
          for(int i=1;i<=cases;i++)
          {
        int d=0;
          int  A = in.nextInt();
           int  B = in.nextInt();
          d=howManyDigits(B);
          int c = resolve(A,B,d);
           System.out.println("Case #" + i + ": " + A + " " + B + " " + c);
      
          }

     }

     
     public  int resolve(int a , int b, int d)
     {
        
         int comp1=0;
         int comp2=0;
   
      int m=0;
      int n=0;
       
         
         for(int j=a;j<=b;j++){
         
        if(d==2) {
             m = this.permuteDigits(j);
             if(a<=m && m<=b){ comp1++;}
         }
        
          if(d==3) {
             m = this.permuteDigits3A(j);
             n = this.permuteDigits3B(j);
             if(a<=m && m<=b){ comp2++;}
             if(a<=n && n<=b){ comp2++;}
         }
        
          
         }
         return (comp1)/2 + comp2;
      
         
         }
         
    
     
     
  
  
int howManyDigits(int x){
  
 if(x<10)   return 1;  

    if(10<=x && x<=99)   return 2;  
     if(100<=x && x<=999)   return 3;  
return 0;
}


int permuteDigits3A(int x){
  
int m =0;
int n = 0;
int t=0;
int f=0;

m=x%100;
m=m%10;
n = x/100;
f=x/10;
f=f%10;
t = m*100+n + f*10;
if((m==n && n==f) ||   f==0) t=0;
return t;
}

int permuteDigits3B(int x){
  
int m =0;
int n = 0;
int t=0;
int f=0;

m=x%100;
n = x/10;
f=x%100;
t = m*100+n;
if((m==n && n==f) ||   m==0 ) t=0;
return t;
}

int permuteDigits(int x){
  
int m =0;
int n = 0;
int t=0;

m=x%10;
n = x/10;
t = m*10+n;
if(m==n || n==0 || m==0 ) t=0;
return t;
}

}

