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.util.Arrays;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws Throwable {
		long init = System.currentTimeMillis();
		int MAX = 2000001;
		//int MAX = 201;
		int arr[][] = new int[MAX][];
		{
			for (int i = 1; i < MAX; i++) {
				TreeSet<Integer> set = new TreeSet<Integer>();
				set.add(i);
				String num = Integer.toString(i);
				for (int j = 1; j < num.length(); j++) {
					String newNum = num.substring(j) + num.substring(0, j);
					if (newNum.charAt(0) != '0') {
						int n = Integer.parseInt(newNum);
						if (n > i && !set.contains(n)) {
							set.add(n);
						}
					}
				}
				set.remove(i);
				arr[i] = new int[set.size()];
				{
					int j = 0;
					for (Integer n : set) arr[i][j++] = n;
				}
			}
		}
		
		long end = System.currentTimeMillis();
		BufferedReader in = new BufferedReader(new FileReader("C-small-attempt0.in"));
		
		for (int i = 0, n = Integer.parseInt(in.readLine().trim()); i < n; i++) {
			String s[] = in.readLine().trim().split(" +");
			int a = Integer.parseInt(s[0]), b = Integer.parseInt(s[1]);
			int c = 0;
			for (int j=a; j<=b; j++) {
				for (int k=0, d; k<arr[j].length && (d=arr[j][k]) <= b; k++) c++;
			}
			System.out.println("Case #"+(i+1)+": "+c);
		}
		//System.out.printf("%.2f seconds%n", (end - init) / 1000.);
	}
}
