import java.io.*;

class code1
{
	public static void main(String args[]) throws Exception 
	{
		File ii = new File ("C-small-attempt1.in");
		FileInputStream fis = new FileInputStream(ii);
		BufferedReader  br = new BufferedReader(new InputStreamReader (fis));
		int cases = Integer.parseInt(br.readLine());
		FileOutputStream fout = new FileOutputStream ("output.txt");
		DataOutputStream dout = new DataOutputStream (fout);
		int total=0;
		for(int i=0;i<cases;i++){
		String temp = br.readLine();
		String parts [] = temp.split(" ");
		int lower = Integer.parseInt(parts[0]);
		int upper = Integer.parseInt(parts[1]);
		System.out.println(lower+" "+upper);
		
		for(int j=lower;j<=upper;j++)
		{
			int abc = j;int length=0;
			if(j<10)continue;
			while (abc!=0){abc/=10;length++;}
			abc=j;
			for(int m=0;m<length-1;m++){
				int shift = abc%10;
				abc=abc/10;
				System.out.println("hi "+j);
				abc=abc+shift*power(10,length-1);
				if(abc<=upper&&shift!=0&&abc>j)total++;
				System.out.println(total);
			}
		}
 		dout.writeBytes("Case #"+(i+1)+ ": "+total+"\n");
 		total=0;
		}//for close
		
	}

	private static int power(int i, int j) {
		int no=1;
		for(int a=0;a<j;a++){no=10*no;}
		return no;
	}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;



public class RecycledNumbers {

	static String inputLargeFile = "C-large.in";
	static String inputSmallFile = "C-small-attempt0.in";
	
	static String outSmallFile = "C-small-attempt0.out";
	static String outLargeFile = "C-large.out";
	
	static BufferedReader br ;
	static PrintWriter out ;
	public static void main(String[] args) throws Exception{
		
		br = new BufferedReader(new InputStreamReader(new FileInputStream(inputSmallFile)));
		out = new PrintWriter(new File(outSmallFile));
		
		String input = br.readLine();
		
		int testcases = Integer.parseInt(input.trim());
		
		for (int i = 0; i < testcases; i++) {
			   String range =  br.readLine();
			   String[] numbers = range.split(" ");
			     
			   int A = Integer.parseInt(numbers[0].trim());
			   int B = Integer.parseInt(numbers[1].trim());
               String part1=null;
               String part2=null;
               int count=0;
               int m =0;
               int endIndex =0;
               int beignIndex=0;
               
               String number = null; 
               String pair = null;
               
			   for(int n=A;n<=B;n++ ){      
		               
		              number = String.valueOf(n);
		              endIndex = number.length()-1;
		              
		             int last=0;
					 for(int p=endIndex;p>0;p--){
						 
						pair =  number.substring(p)+number.substring(beignIndex,p);
					    m=Integer.parseInt(pair); 
						
					  
					    if(m>n&&m<=B&&m!=last){
							
							count++;
							last=m;
							
							//out.println("count : " + count);
						}
					 
					 } 
				   }
				   
			   out.println("Case #"+ (i+1)+ ": " + count);	   
		}
			   
			   
			
			 	   				   
		out.close();
		br.close();
	   
			
		}
		
		
	}


