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));
			
		}
		
		
		

	}
	
	
}
//Shreyas Garg
//sgbasketball3
   import java.io.*;
   import java.util.*;
   import java.lang.*;
   public class Recycle
   {
      public static int count = 0;
      public static int MAX = 0;
      public static int MIN = 0;
      public static Set<Pair> set = new HashSet<Pair>();
      public static void main(String[] args) throws Exception
      {
         Scanner sc = new Scanner(new File("C-small-attempt0.in.txt"));
         PrintStream outfile = new PrintStream(new FileOutputStream("recycle.out.txt"));
         int N = sc.nextInt();
         for(int y = 0; y < N; y++)
         {
            int A = sc.nextInt();
            int B = sc.nextInt();
            MIN = A;
            MAX = B;
            if( A < 10 && B < 10)
               outfile.println("Case #" + (y+1) + ": 0");
            else
            {
               for(int x = A; x < B; x++)
                  findPossibilities(x);
               outfile.println("Case #" + (y+1) + ": " + set.size());
               set = new HashSet<Pair>();
            }
         }
      }
      public static void findPossibilities(int y)
      {
         String s = Integer.toString(y);
         for(int x = 1; x < s.length(); x++)
         {
            String one = s.substring(x);
            String two = s.substring(0,x);
            String com = one + two;
            int temp = i(com);
            com = Integer.toString(temp);
            if(temp > MIN && temp <= MAX && temp > y)
            {
               //System.out.println(s + " " + com);
               count++;
               set.add(new Pair(y,temp));
            }
         }
      
      }
      public static int i(String s)
      {
         return Integer.parseInt(s);
      }
   }
   class Pair
   {
      public int x;
      public int y;
      public Pair(int one, int two)
      {
         x = one;
         y = two;
      }
      public boolean equals(Object z)
      {
         if(hashCode() == z.hashCode())
            return true;
         return false;
      }
      public int hashCode()
      {
         String one = Integer.toString(x);
         String two = Integer.toString(y);
         return (one + two).hashCode();
      }
   }