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.FileInputStream;
import java.io.InputStreamReader;

public class main {

	public static void main(String[] args) {
		// inputãã¡ã¤ã«ãèª­ã¿è¾¼ã¿
		BufferedReader bufferReader = null;
		String str = "";
		try {
			bufferReader = new BufferedReader(new InputStreamReader(
					new FileInputStream("/Users/yago/Documents/in.txt"),
					"UTF-8"));
			// ä¸è¡ãã¤èª­ã¿è¾¼ã¿
			int probs = 0;
			while ((str = bufferReader.readLine()) != null) {
				if (str.length() > 2) {
					probs++;
					calc(str, probs);
				}
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		} finally {
			try {
				if (bufferReader != null) {
					bufferReader.close();
				}
			} catch (Exception e) {
			}
		}
	}

	private static void calc(String str, int probNum) {
		Integer n1, n2, ansCnt = 0;
		String[] strAry = str.split(" ");
		n1 = Integer.valueOf(strAry[0]);
		n2 = Integer.valueOf(strAry[1]);
		for (int i = n1; i <= n2; i++) {
			for (int j = i + 1; j <= n2; j++) {
				if(String.valueOf(j).length() == 1)
					break;
				if (String.valueOf(j).length() == 2) {
					if (String.valueOf(j).charAt(0) == String.valueOf(i)
							.charAt(1)
							&& String.valueOf(j).charAt(1) == String.valueOf(i)
									.charAt(0))
						ansCnt++;
				} else if ((String.valueOf(j).charAt(0) == String.valueOf(i)
						.charAt(1)
						&& String.valueOf(j).charAt(1) == String.valueOf(i)
								.charAt(2) && String.valueOf(j).charAt(2) == String
						.valueOf(i).charAt(0))
						|| String.valueOf(j).charAt(0) == String.valueOf(i)
								.charAt(2)
						&& String.valueOf(j).charAt(1) == String.valueOf(i)
								.charAt(0)
						&& String.valueOf(j).charAt(2) == String.valueOf(i)
								.charAt(1)) {
					ansCnt++;
				}
			}
		}

		System.out.println("Case #" + probNum + ": " + ansCnt);
	}
}