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.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Scanner;


public class abc {
	public static void main(String args[]) 
	{
		int x ,y,j,k,ans=0;
		int tcount =0;
		try{
			  // Create file 
			  FileWriter fstream = new FileWriter("C-large.out");
			  BufferedWriter out = new BufferedWriter(fstream);
			 
		
      
		
		 Scanner myfile;
		try {
			myfile = new Scanner(new FileReader("C-large.in"));
				 int testcases = myfile.nextInt();
         while (testcases != 0 || myfile.hasNextInt())  
         {          // Read file content using a while loop
        	 ans =0; 
        	 x = myfile.nextInt();
        	 y = myfile.nextInt();
        	 
        // System.out.println(x + y);
		
		int divby = 1;
		for(k = x;k>=10;k/=10)
		{
			divby = divby *10;
		}
		
		int divdivby = 1;
		for(j=x;j<=y;j++)
		{
			int[] ar = new int[20];
			int itr = 0;
			for(divdivby = divby ; divdivby != 1; divdivby/=10)
		  	
			{
			int m = j % divdivby;
			int n = j /divdivby;
			m  = m *(divby /divdivby)*10;
			m = m+n;
			for(int l=0;l<=itr;l++)
			{
				if(ar[l] == m)
				{	m=0;break;}
				
			}
			if(m!=0)
			{
				ar[itr] = m;
				itr++;
			}
			if(m > j && m <= y && m >= x)
				{
				ans++;
				//System.out.println(m +"-- "+j);
				}
			
			}
		}
		
		
		out.write("Case #"+ ++tcount+": "+ans+"\n");
		
	//	System.out.println(ans);
		testcases--;
	}

		  
         
         myfile.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} // Reading file using Scanner

		out.close();
		}catch (Exception e){//Catch exception if any
			  System.err.println("Error: " + e.getMessage());
			  }
		
		
	}

	
}
