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

}

package codejam;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Set;

public class C {
    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new FileReader("file.in"));
        PrintStream out = new PrintStream(new FileOutputStream("file.out"));

        int nLines = Integer.parseInt(in.readLine());

        String[] s;

        for (int i = 1; i <= nLines; i++) {
            s = in.readLine().split(" ");

            int nA = Integer.valueOf(s[0]);

            int nB = Integer.valueOf(s[1]);

            int result = 0;

            Set<String> set = new HashSet<String>();

            if (nB > 10) {

                int start = Math.max(nA, 11);

                for (int j = start; j <= nB; j++) {

                    String st = String.valueOf(j);

                    for (int k = 1; k < st.length(); k++) {

                        String res = st.substring(k) + st.substring(0, k);
                        if (!res.startsWith("0") && !st.equals(res)
                                && st.length() == res.length()) {

                            int v = Integer.valueOf(res);

                            if (v <= nB && j < v) {
                                set.add(st + "," + res);
                            }

                        }

                    }

                }

            }
            result = set.size();

            out.println("Case #" + i + ": " + result);
        }

        in.close();
        out.close();
    }
}
