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.io.*;
class Recycled_Numbers
{
  public static void main(String arg [])
  {
    int check =-456;
       String m="";
    int counter =0;
    int calculate =0;
    String sub="";
    int mi =0;
     int ma=0;
    String path;
    String first,second;
    int numberOfLoops=0;
     Scanner read = new Scanner(System.in);
    System.out.println("pls enter your file");
    path = read.nextLine();
    
   
    BufferedWriter bw;
    try
    {
      File  fobj = new File(path);
      Scanner sc = new Scanner(fobj);
      bw =new BufferedWriter( new FileWriter("RecycleOutput.txt"));
      int tests = sc.nextInt()  ,meter = 1;
      while (meter <= tests)
      {  
     
        mi= sc.nextInt();
          ma =sc.nextInt();
     
    while(mi<=ma)
    {
         counter =0;  
        m = mi+"";
     
     
      while(counter <m.length()-1)
      {
        numberOfLoops=m.length()-1;
        second = m.substring(numberOfLoops -counter);
        first = m.substring(0,numberOfLoops-counter);
        sub = second+first;
     
        if ((Integer .parseInt(sub)>mi)&&(Integer .parseInt(sub)<=ma)&&(Integer .parseInt(sub)!=check) )
        {
            
          calculate++;
        check= Integer .parseInt(sub);
        }
        
        counter++;
      }
      
      
      mi++;
    } 
    bw.write("Case #"+meter+": " +calculate );
    bw.newLine();
    calculate =0;
    meter++;
    } 
    bw.close();
      }//end of try
    catch(IOException e)
    {
      System.out.println(e);
    }
   
    }    
}