
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;

public class Recycle
{
	public static void main(String[] args)
	{
/*		Set<Integer> perms = getPermutations(123456);
		
		for(Integer i: perms)
			System.out.println(i);*/
	
		try
		{
			Scanner s = new Scanner(new File("recycle.in"));
			BufferedWriter w = new BufferedWriter(new FileWriter(new File("recycle.out")));
			int numCases = s.nextInt();
			s.nextLine();
			
			for(int n = 1;n <= numCases; n++)
			{
				int A = s.nextInt();
				int B = s.nextInt();
				int count = 0;
				for(int k = A; k <= B; k++)
				{
					count += getNumPairs(k, B);
				}
				
				w.write("Case #" + n + ": " + count + "\n");
			}
			
			w.flush();
			w.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static int getNumPairs(int n, int B)
	{
		Set<Integer> possibles = getPermutations(n);
		int count = 0;
		for(Integer i : possibles)
			if(i > n && i <= B)
				count++;
		return count;
	}
	
	public static Set<Integer> getPermutations(int n)
	{
		Set<Integer> perms = new TreeSet<Integer>();
		char[] digits = String.valueOf(n).toCharArray();
		
		for(int firstPos = 1; firstPos < digits.length; firstPos++)
		{
			String toBuild = "";
			for(int k = 0; k < digits.length; k++)
				toBuild += digits[(firstPos + k) % digits.length];
			perms.add(Integer.parseInt(toBuild));
		}
		return perms;
	}
	

}


import java.util.Scanner;

/**
 *
 * @author krishna
 */
public class Recycled {
   

    public static void main(String[] args) {
        Program();
    }

    public static void Program() {
        Scanner inp = new Scanner(System.in);
        String line;
        String nor[];
        int num1, num2;
        int test = Integer.parseInt(inp.nextLine());
        int num = 1;
        while (num <= test) {
            line = inp.nextLine();
            nor = line.split(" ");
            num1 = Integer.parseInt(nor[0]);
            num2 = Integer.parseInt(nor[1]);
            System.out.println("Case #"+num+": "+CountNum(num1, num2));
            num++;
        }


    }

    public static int CountNum(int num1, int num2) {
        int count = 0;
        int goMax[]={9,99,999,9999,99999,999999};
        int goMin[]={0,10,100,1000,10000,100000};
        int length;
        for (int x = num1; (x < num2) && !leadingZeros(x); x++) {
            {
                 length=Integer.valueOf(x).toString().length();
                 count +=found(x,Math.max(num1,(int)goMin[length-1]),(int)Math.min(num2,goMax[length-1]));
                     
            }
        }

        return count;
    }

    private static int found(int num, int min, int max) {
     
        int part1;
        int part2;
        int zero=10;
        String join;
        int rem;
        int count=0;
          while(num/zero !=0)
          {
              rem=num%zero;
           
              part1=rem;
              part2=num/zero;
              
                
              join=part1+""+part2;
              zero =zero*10;
             if(Integer.parseInt(join)>=min && Integer.parseInt(join)<=max && Integer.parseInt(join) > num  && checkLength(num,join)  ){
                  
                  count++;
              }
             
              if(alternate(join,max))
                  count--;
          }
        return count;
    }
 public static boolean leadingZeros(int num)
{
  String str=num+"";
  if(str.charAt(0)=='0')
      return true;
  else
      return false;
      
}
 public static boolean checkLength(int num1,String str2)
 {
     String str1=num1+"";
     if(str1.length() == str2.length())
         return true;
     else
         return false;
 }
 public static boolean alternate(String str,int max)
 {
     String str2=str.substring(1);
     str2=str2+str.charAt(0);
     if(str==str2)
     {
         return true;
     }
     else
         return false;
 }
}

