import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gcj2012;

/**
 *
 * @author allegea
 */
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;

/**
 *
 * @author Allegea
 */
public class RecycledNumbers {
 
    public static void main(String[] args) throws IOException,FileNotFoundException{
        
       String name = "C-small-attempt0";
        
        BufferedReader in   = new BufferedReader(new FileReader(name+".in"));
        
        // BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        FileWriter archivo = new FileWriter(name+".out");
        PrintWriter out = new PrintWriter(archivo);
        out.flush();

         
           String line;
           line = in.readLine();
           int cases = Integer.parseInt(line);
           int act = 0;
            while (act++<cases) 
            {
                StringTokenizer x = new StringTokenizer(in.readLine());
                int a = Integer.parseInt(x.nextToken());
                int b = Integer.parseInt(x.nextToken());
                HashSet<String> set = new HashSet<String>();
                
                for(int i=a;i<=b;i++){
                    String w = String.valueOf(i);
                    for(int j=1;j<w.length();j++){
                         String ans = w.substring(j,w.length())+w.substring(0, j);
                         if(!ans.equals(w)){
                             int q = Integer.parseInt(ans);
                             if(q<=b && q>=a)
                             {
                                 String other = Math.min(i, q)+"-"+Math.max(i, q);
                                 set.add(other);
                             }
                         }
                    }
                    
                }
                
               // System.out.println(set.size()+" - "+set);
                
                
                System.out.println("Case #"+act+": "+set.size());
               out.println("Case #"+act+": "+set.size());
              // System.out.println(line); 
                
            }


        in.close();
        out.close();
        System.exit(0);

        

        
        
    }
   


}

