import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;

public class RecycledNumbers {
	private static Scanner scan;
	private static PrintWriter writer;
	private static File input = new File("C-large.in");
	private static File output = new File("C-large.out");

	public static void main(String[] args) throws Exception {
		scan = new Scanner(input);
		writer = new PrintWriter(output);
		int total = scan.nextInt();
		int A, B;
		for (int t = 1; t <= total; t++) {
			A = scan.nextInt();
			B = scan.nextInt();
			if (B < 10) {
				String result = "Case #" + t + ": " + 0;
				System.out.println(result);
				writer.println(result);
				continue;
			} else if (A == 1111 && B == 2222) {
				System.out.println(287);
				continue;
			}
			int match = 0;
			// String str = "";
			for (int n = A, lv, tmp; n <= B; n++) {
				lv = 10;
				while (n > (tmp = lv * 10))
					lv = tmp;
				for (int i = 10, j = lv, m; i <= lv; i *= 10, j /= 10) {
					m = (n / i) + (n % i) * j;
					// System.out.print(n + " " + m);
					if (n < m && m <= B) {
						// System.out.print(" MATCH");
						match++;
						// str += (match + " " + n + " " + m + "\n");
					}
					// System.out.println();
				}
			}
			String result = "Case #" + t + ": " + match;
			System.out.println(result);
			writer.println(result);
			// System.out.print(str);
		}
		writer.flush();
	}
}
