package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}

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

public class QualificationRoundC {
    public static int power(int i, int p){
        int k = 1;
        for(int j = 0; j < p; j++)
            k *= i;
        return k;
    }
    public static int recycle(int n, int k){
        int d = power(10, k);
        int e = power(10, numDigits(n) - k);
        int right = n % d;
        int left = n / d;
        return right * e + left;
    }
    public static int numDigits(int n){
        int i = 1, k = 0;
        while(n / i > 0){
            i *= 10;
            k++;
        }
        return k;
    }
    public static Set<Integer> getRecycledNumbers(int n){
        int digits = numDigits(n);
        Set<Integer> recycled = new HashSet<Integer>(digits - 1);
        for(int i = 0; i < digits; i++){
            int m = recycle(n, i);
            recycled.add(m);
        }
        return recycled;
    }
    public static void main(String[] args) throws IOException {
        String inFile = args[0];
        String outFile = args[0].replaceAll("\\.in$", ".out");

        FileInputStream fileInputStream = new FileInputStream(inFile);
        Scanner scanner = new Scanner(fileInputStream);
        FileWriter fileWriter = new FileWriter(outFile);
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

        int cases = scanner.nextInt();

        for(int i = 1; i <= cases; i++){
            int A = scanner.nextInt(), B = scanner.nextInt();
            int count = 0;

            for(int n = A; n < B; n++){
                Set<Integer> recycled = getRecycledNumbers(n);
                Iterator<Integer> it = recycled.iterator();
                while(it.hasNext()){
                    int m = it.next();
                    if(n < m && m <= B)
                        count++;
                }
            }

            String answer = String.format("Case #%d: %d\n", i, count);
            System.out.print(answer);
            bufferedWriter.write(answer);
        }

        bufferedWriter.close();
        fileWriter.close();
        scanner.close();
        fileInputStream.close();

    }
}
