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.*;

import java.lang.*;

class RotateNumber {   
	public static long RotateNumber(long number, long A, long B)
	{
		long start = number;
		long sum = 0;
		int numdigits = (int) Math.log10((double)number); // would return numdigits - 1
		int multiplier = (int) Math.pow(10.0, (double)numdigits);
		while(true)
		{
			long q = number / 10;
			long r = number % 10;
			number = number / 10;
			number = number + multiplier * r;
			if(number == start)
				break;
			if (start < A) break;
			if (start >= A && start < number && number <= B) {
				sum++;
			}
		}
		return sum;
	}
	public static void main(String[] args) throws IOException {

		FileInputStream fstream = new FileInputStream("/tmp/codejam/A-small-practice.in");
		//DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
		PrintWriter out = new PrintWriter(new File("/home/peeyushk/tmp/output.ou"));
		String strLine;
		strLine = br.readLine().trim();
		int test = Integer.parseInt(strLine);
		for (int i=0;i<test;i++) {
			strLine = br.readLine().trim();
			long count = 0;
			String[] strings = strLine.split(" ");
			long A = Integer.parseInt(strings[0].trim());
			long B = Integer.parseInt(strings[1].trim());
			for (long num = A; num <= B; num++) {
				count = count + RotateNumber(num, A, B);
			}
			int k = i+1;
			out.println("Case #" + k + ": " + count);
		}
		out.flush();
		out.close();
		br.close();
	}
}