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.HashSet;
import java.util.Scanner;

public class Numbers {

    public static void main(String[] args) throws IOException {
        Numbers numbers = new Numbers();
        numbers.findNumbers();
    }

    public void findNumbers() throws IOException {
        Scanner sc = new Scanner(new File("D:/testing/a.txt"));
        BufferedWriter bf = new BufferedWriter(new FileWriter("D:/testing/b.txt", false));
        HashSet<String> hs = new HashSet<String>();

        int T = sc.nextInt();
        for (int i = 1; i <= T; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            hs.clear();
            
            int digits = (int) Math.log10(a);

            for (int n = a; n <= b; n++) {
                for (int j = 1; j <= digits; j++) {
                    int m = swapDigits(n, j);
                    if (n < m && m <= b) {
                        hs.add(String.valueOf(m) + String.valueOf(n));
                    }
                }
            }
            int val=hs.size();
            System.out.println("Case #" + i+": "+val);
            bf.write("Case #" + i+": "+val+ "\n");
        }
        bf.close();
    }

    public int swapDigits(int val, int d) {
        int power=(int)Math.pow(10, d);
        int x = val/power;
        int y = val % power;
        return y * (int) Math.pow(10, (int) Math.log10(x) + 1) + x;
    }
}
