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 codejam.practice;

/**
 *
 * @author Saikat Roy
 */
import java.io.*;
public class Main2 {
    
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    public void input() throws IOException
    {
       int k=1;
       int n=Integer.parseInt(br.readLine());
       while(n--!=0)
       {
           int flag=0;
           String[] str2=new String[25];
           String str1=br.readLine();
           String stcpy="";
           str2=str1.split("[ ]");
           int i=(int) Math.pow(10,str2[0].length()-1);
           for(int x=Integer.parseInt(str2[0]);x<=Integer.parseInt(str2[1]);x++)
           {
             if(i!=1){
                 String mx=String.valueOf(x);
                 
                 for(int l=1;l<mx.length();l++)
                 {
                     int mark=1;
                     String st="";
                     for(int m=l;m<mx.length();m++)
                     st+=mx.charAt(m);
                     for(int m=0;m<l;m++)
                         st+=mx.charAt(m);
                     //System.out.println(st);
                     if(Integer.parseInt(st)>Integer.parseInt(mx)&&Integer.parseInt(st)<=Integer.parseInt(str2[1]))
                     {
                         if(stcpy.equals(st))
                         mark=0;
                         
                         if(mark!=0)
                         {
                        flag++;
                        stcpy="";
                        stcpy+=st;
                        //System.out.println(mx+":"+st);
                         }}
                 }
             }  
             else
                 flag=0;
               
           }
          System.out.print("Case #"+k+": "+flag);
          System.out.println();
           //System.out.println(Integer.parseInt("201")<Integer.parseInt("012")?true:false);
           k++;
       }
           }
     public static void main(String[] args) throws IOException {
        Main2 ob=new Main2();
        ob.input();
    }
    
}
