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.io.BufferedReader;
import java.io.FileReader;
import java.sql.Array;
import java.util.ArrayList;
import java.util.concurrent.BlockingDeque;

public class RN {

    public static void main (String[] args) throws Exception
    {

		BufferedReader sr = new BufferedReader(new FileReader("c:\\Projects\\RN.txt"));

		int total = Integer.parseInt(sr.readLine());

        for (int i=0; i<total; i++)
        {
            String[] tokens = sr.readLine().split(" ");
            int A = Integer.parseInt (tokens[0]);
            int B = Integer.parseInt (tokens[1]);


            int res = solve (A, B);
            System.out.printf("Case #%d: %d\n", i+1, res);

        }
    }

    private static int[] decimals (int A)
    {
        int rest = A;
        int num = 0;

        while (rest > 0)
        {
            rest = rest / 10;
            num++;
        }

        int[] result = new int[num];
        for (int i=0; i<num; i++)
        {
            result[num-i-1] = A % 10;
            A = A / 10;
        }

        return result;
    }

    private static int toNumber (int[] dec, int offset)
    {

        int total1 = 0;
        for (int i=0; i<offset; i++)
        {
            total1 = total1 * 10 + dec[i];
        }

        int total2 = 0;
        for (int i=offset; i<dec.length; i++)
        {
            total2 = total2 *10 + dec[i];
        }

        return total1 + total2 * (int)Math.pow(10, offset);
    }


    public static int solve (int A, int B)
    {
        if (B <= A) return 0;

        int[] decA = decimals(A);
        int[] decB = decimals(B);

        if (decA.length < decB.length)
        {
            int border = (int) Math.pow(10, decA.length) - 1;
            return solve(A, border) + solve(border+1, B);
        }

        int total = 0;
        for (int Curr = A; Curr < B; Curr++)
        {
            int[] dec = decimals(Curr);

            //int[] variants = new int[dec.length];
            ArrayList<Integer> variants = new ArrayList<Integer>();
            int first = dec[0];
            for (int i=1; i<dec.length; i++)
            {
                if (dec[i] >= first)
                {
                    int candidate = toNumber(dec, i);
                    if (candidate > Curr &&
                        candidate <= B)
                    {
                        if (!variants.contains(candidate))
                        {
                            variants.add(candidate);
                            total++;
                        }
                    }
                }
            }
        }
        return total;
    }
}
