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

	}
	
	
}
import java.util.*;
import java.io.*;

public class Recycle
{
  public static boolean sameNumbers(int n, int m, int length, int i)
  {
    
    char[] nArray = (n + "").toCharArray();
    char[] mArray = (m + "").toCharArray();
    for (int j = 0; j < length; j++)
    {
      //System.out.println(j + " " + i + " " + m + " " + mArray.length);
      if (Arrays.binarySearch(nArray, mArray[i]) == -1) return false;
      
    }

    return true;
  }
  public static boolean check(int n, int m, int a, int b, int i)
  {

    if (n > m) return false;
    else if (n == m) return false;
    else if (n < a) return false;
    else if (m > b) return false;
   // else if (!sameNumbers(n,m,(n + "").length(), i)) return false;
    // System.out.println(n + " " + m);
    return true;
  }
  public static void main (String []args) throws IOException
  {
    final String INPUT_FILE = "C-small-attempt0.in";
    final String OUTPUT_FILE = "out3.out";
    
    BufferedReader input = new BufferedReader(new FileReader(INPUT_FILE));
    PrintWriter out = new PrintWriter(new FileWriter(OUTPUT_FILE));
    
    int repeats = Integer.parseInt(input.readLine());
    
    for (int j = 0; j < repeats; j++)
    {
      StringTokenizer g = new StringTokenizer(input.readLine());  
      
      int count = 0;
      int a = Integer.parseInt(g.nextToken());
      int b = Integer.parseInt(g.nextToken());
      int aLength =  (a + "").length();
      if (aLength == 1) out.println("Case #" + (j + 1) + ": 0");
      else 
      {
        int arrayCounter = 0;
        for (int k = a; k < b; k++)
        {
          for (int i = 1; i < aLength;i++)
          {
            String kString =  k + "";
            
            //System.out.println(a + " " + aLength + " " + i);
            
            String mString1 = kString.substring(i,aLength);
            String mString2 = kString.substring(0,i);
            
            //System.out.println(kString + " " + mString1 + " " + mString2);
            
            int m = Integer.parseInt(mString1 + mString2);
            
            if (check(k,m,a,b,i))
            {
              count++;
            }
          }
        }
        out.println("Case #" + (j + 1) + ": " + count);
      }
    }
    out.close();
    input.close();
  }
}