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);
		}
	}
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package codejam;
import java.io.*;
/**
 *
 * @author Nah-Abiah
 */
public class recycledNumbers {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try{
            FileInputStream fstream = new FileInputStream("C-large.in");
            
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            
            int testCount = 0;
            int caseCount = 1;
            String writeFile = "";
            while ((strLine = br.readLine()) != null)   {
                if(testCount == 0){
                    testCount = Integer.parseInt(strLine);
                } 
                else{                    
                    String[] ints = strLine.split(" ");
                    int n = Integer.parseInt(ints[0]);
                    int limit = Integer.parseInt(ints[1]);                    
                    int num = 0;
                    if(ints[0].length() != 1){
                        while (n < limit){
                            int count = 1;
                            
                            while(count < ints[0].length()){
                                String m = String.valueOf(n).substring(count)+String.valueOf(n).substring(0, count);
                                if((n<Integer.parseInt(m)) && (Integer.parseInt(m)<= limit)){
                                    num++;
                                }
                                count++;
                            }
                            n++;
                        }
                    }
                    writeFile += "Case #"+caseCount+": "+num+"\r\n";
                    caseCount++;
                }
            }
            //Close the input stream
            in.close();
            
            try{
                // Create file 
                FileWriter filestream = new FileWriter("outputLarge.txt");
                BufferedWriter out = new BufferedWriter(filestream);
                out.write(writeFile);
                //Close the output stream
                out.close();
            }
            catch (Exception e){//Catch exception if any
                System.err.println("Error: " + e.getMessage());
            }
        }
        catch (IOException | NumberFormatException e){//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
    }
}
