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

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}


import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author leonardo
 */
public class RecyclingNumbers {
  
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long inputSize = Integer.parseInt(scanner.nextLine());
        
        for (long i = 1; i <= inputSize; i++) {
            String[] input = scanner.nextLine().split(" ") ;
            
            /* No solution exists. */
            if (input.length == 1)
                continue ;
            
            long a = Long.parseLong(input[0]) ;
            long b = Long.parseLong(input[1]) ;
            System.out.println("Case #" + i + ": " + countRecyclablePairs(a, b)) ;
        }        
    }
    
    private static long countRecyclablePairs(long a, long b) {
        if (a == b)
            return 0 ;        
                
        long count = 0 ;
        for(long n = a; n <= b; n++) {                   
                                   
            LinkedList<Long> digits = toLinkedList(n) ;
            Set<Long> counted = new HashSet<Long>() ;
            
            for(long i = 0; i < digits.size(); i++) {                                
                digits.addFirst(digits.removeLast()) ;
                long m = toNumber(digits) ;
                
                if (! counted.contains(m) && n < m && m <= b) {
                    counted.add(m) ;
                    count++ ;
                }
            }            
        }
        return count ;
    }    
    
    private static LinkedList<Long> toLinkedList(long number) {
        LinkedList<Long> digits = new LinkedList<Long>() ;                
        long remainer = 0 ;
        
        while(number >= 10) {
            remainer = number % 10 ;
            digits.addFirst(remainer);
            number = number / 10 ;
        }
        
        digits.addFirst(number) ;        
        return digits ;
    }    
    
    private static long toNumber(LinkedList<Long> digits) {
        long number = 0 ;
        long expoent = digits.size() - 1 ;
        
        for(long d : digits) {
            number += d * Math.pow(10, expoent) ;
            expoent-- ;
        }
        
        return number ;
    }
}
