package codejam;

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

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.*;

public class main {

    int numberPeriod(int n, int len) {
        if (len == 2 && n / 10 == n % 10) return 1;
        if (len == 4 && n % 100 == n / 100) return 2;
        if (len == 6 && n % 100 == n / 10000 && n % 100 == n / 100 % 100) return 2;
        if (len == 6 && n % 1000 == n / 1000) return 3;
        return len;
    }

    int numberLength(int n) {
        int len = 0;
        while (n > 0) {
            n /= 10;
            len++;
        }
        return len;
    }

    main() throws FileNotFoundException {
        Scanner sc = new Scanner(new File("C-small-attempt0.in"));
        PrintWriter out = new PrintWriter("result.txt");
        int tests = sc.nextInt();
        for (int t = 1; t <= tests; t++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int l = numberLength(a);
            int tt = (int) Math.pow(10, l - 1);
            int r = 0;
            for (int j = a; j <= b; j++) {
                int cr = j;
                int val = j;
                int per = numberPeriod(j, l);


                for (int k = 0; k < per; k++) {
                    int c = val % 10;
                    val = val / 10 + c * tt;
                    if (val > cr && val <= b) {
                        r++;
                    }
                }
            }
            out.printf("Case #%d: %d\n", t, r);
        }
        out.flush();
    }

    public static void main(String[] args) {
        try {
            main m = new main();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}