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 recycle;

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.ArrayList;

/**
 *
 * @author admin
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        // TODO code application logic here
         FileReader fr=new FileReader("C-small-attempt0.in");
        BufferedReader br=new BufferedReader(fr);
        FileWriter fw=new FileWriter("result.txt");
        PrintWriter pw=new PrintWriter(fw);
getOutPut(br,pw);
pw.close();
    }
    public  static void getOutPut(BufferedReader br,PrintWriter pw) throws IOException {
        int t=Integer.parseInt(br.readLine());
       int A,B;
        for(int i=0;i<t;i++){
        String[] s=br.readLine().split(" ");
         A=Integer.parseInt(s[0]);
         B=Integer.parseInt(s[1]);
           
        pw.print("Case #"+(i+1)+": "+recyles(A,B));
         
        pw.println();
        }
    }

    public  static int recyles(int A,int B) {
        ArrayList<Integer> num;
        String Sa,Sb;
        int count=0;
        Sa=Integer.toString(A);
        Sb=Integer.toString(B);
        for(int i=A;i<=B;i++){
            num=new ArrayList<Integer>();
          for(int j=Sa.length()-1;j>0;j--){
            Sa=Integer.toString(i).substring(j)+Integer.toString(i).substring(0,j);
            if(Integer.parseInt(Sa)<=B&&Sa.charAt(0)!='0'&&i<Integer.parseInt(Sa)){
                if(!num.contains(Integer.parseInt(Sa))){
                num.add(Integer.parseInt(Sa));
                count++;
                }

              }
          }
        }
        
        return count;
    }

}
