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.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {

        String filename = "C:\\Users\\irene\\Desktop\\input.txt";
        List<String> inputLines = readInput(filename);
        int i = 0;
        for (String line : inputLines) {
            String[] limits = line.split("\\s+");
            RecycledNumbers rn = new RecycledNumbers(Integer.parseInt(limits[0]), Integer.parseInt(limits[1]));
            int result = rn.getDistinctPairsCount();
            System.out.print("Case #" + (i + 1) + ": " + result);
            System.out.println();
            i++;
        }
    }

    private static List<String> readInput(String filename) throws IOException {
        BufferedReader in
                = new BufferedReader(new FileReader(filename));

        Integer totalLines = Integer.parseInt(in.readLine());
        ArrayList<String> lines = new ArrayList<String>(totalLines);
        for (int i = 0; i < totalLines; i++) {
            lines.add(in.readLine());
        }
        return lines;
    }
}
