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;
	}

}


public class ProbQ3 {
	public static void main(String[] args) {

		String fileContent = CodeJamTools.readFileAsString("c:\\temp\\inputQ3.txt");
		String[] rows = fileContent.split("\\n");
		int T = new Integer(rows[0]);
		String output = "";

		int counter = 1;

		for (int i=0; i<T; i++) {
			System.out.println(rows[counter]);
                        long[] data = CodeJamTools.readLongsFromRow(rows[counter]);
			counter++;

                        long A = data[0];
                        long B = data[1];

                        long c = 0;

                        for (long j=A; j<B; j++) {
                            for (long k=j+1; k<=B; k++) {
                                c += isValid(j,k);
                            }
                        }

			output += "Case #"+(i+1)+": ";
			output += c;
                        output += "\n";
		}

		System.out.print(output);
		CodeJamTools.writeStringToFile("C:\\Users\\Conny\\Documents\\conny\\own files\\java_workspace\\codejam2\\src\\outputQ3.txt", output);
	}


        private static long isValid(long n, long m) {
            String ns = ""+n;
            String ms = ""+m;
            for (int i=1; i<ns.length(); i++) {
                if (ns.equals(ms.substring(i)+ms.substring(0,i))) {
                    return 1;
                }
            }
            return 0;
        }
}
