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

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}

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

public class ProblemCLarge {

	public static void main(String[] args) throws Exception {

		// Scanner sc = new Scanner(new File("C:\\C-Large.in"));
		Scanner sc = new Scanner(System.in);
		int cases = Integer.parseInt(sc.nextLine().trim());
		for (int i = 0; i < cases; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println("Case #" + (i + 1) + ": " + solve(a, b));
		}
	}

	private static int solve(int a, int b) {
		int count = 0;
		int num_digs = ("" + a).length();
		int[] power = new int[] { 1, 10, 100, 1000, 10000, 100000, 1000000,
				10000000 };

		for (int i = a; i <= b; i++) {
			int[] tmp = new int[10];
			int cnt = 0;

			for (int j = 1; j < num_digs; j++) {
				boolean found = false;
				
				if (i % power[j] > 0) {
					int tmp1 = (i % power[j]) * power[num_digs - j];

					int tmp2 = (i - (i % power[j])) / power[j];

					int tmp3 = tmp1 + tmp2;

					if (cnt == 0) {
						tmp[cnt++] = tmp3;
					} else {
						for (int k = 0; k < cnt; k++) {
							if (tmp3 == tmp[k]) {
								found = true;
							}
						}
						if(!found){
							tmp[cnt++] = tmp3;
						}
					}
				}
			}

			for (int tmp4 : tmp) {
				if (tmp4 >= a && tmp4 <= b && tmp4 != i) {
					//System.out.println(i + " " + tmp4);
					count++;
				}
			}
		}

		return count / 2;
	}

}
