import java.util.*;
import java.io.*;

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
import java.util.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class  Main  {
	
	//ArrayList<Integer> lis = new ArrayList<Integer>();
	//ArrayList<String> lis = new ArrayList<String>();
	//ArrayList<test> lis = new ArrayList<test>();
	static long sum=0;
	
public  static void main(String[] args) throws IOException {
   //googlein.txt C-small-attempt0.in
	Scanner sc =new Scanner(new File("C-large.in"));
	  File file = new File("file.txt");
		PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
	//	sc.useDelimiter("(\\s)+|[,]");
		 int T=sc.nextInt();
		
	 	for(int k=1; k<=T; k++){
	 	 int c=0, a=sc.nextInt(),b =sc.nextInt();
	 	 
	 	 for(int t=a;t<=b;t++){
	 		String s=String.valueOf(t);
	 		
	 		int l=s.length(),g=1; 
	 		ArrayList<Integer> lis = new ArrayList<Integer>();
	 		for(int u=0;u<l;u++)g*=10; 
	 		
	 		for(int u=0,p=10;u<l-1;u++,p*=10){
	 		 //  int h= Integer.parseInt(s.substring(l-u-1,l-u));
	 			//if( h<1  )continue;
	 		   
	 			int e=(t%p)*(g/p),f=t/p,y=e+f;
	 			//db(t,y);
	 		  if( a<=y && y<=b && t<y && !lis.contains(y)){c++; lis.add(y);// db(t,y);
	 		  }	
	 			
	 			
	 	 }
	 
	 		
		 }
	 
	 	pw.println("Case #"+(k)+": "+c);
	 	}
	 	

	 	pw.flush();
	 	pw.close();  }



 

    static int ni(Scanner in){
	return in.nextInt();  
 }


    static void db(Object... os){
	         System.err.println(Arrays.deepToString(os));
 
	}

}
