import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Recycled {
	public static void main(String[] args) throws Exception{
		String inputFile = "C-small-attempt0.in";
		
		BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
		BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output")));
		long num_cases = Long.parseLong(input.readLine());
		int current_case = 0;
		
		while (current_case < num_cases){
			current_case++;
			
			String[] fields = input.readLine().split(" ");
			int A = Integer.parseInt(fields[0]);
			int B = Integer.parseInt(fields[1]);
			int total = 0;
			
			for (int n = A; n < B; n++){
				for (int m = n+1; m <= B; m++){
					if (isRecycled(n,m)) total++;
				}
			}
			
			System.out.println("Case #" + current_case + ": " + total);
			output.write("Case #" + current_case + ": " + total + "\n");
		}
		output.close();
	}

	private static boolean isRecycled(int n, int m) {
		String sn = ""+n;
		String sm = ""+m;
		if (sn.length() != sm.length()) return false;
		int totaln = 0, totalm = 0;
		for (int i = 0; i < sn.length(); i++){
			totaln += sn.charAt(i);
			totalm += sm.charAt(i);
		}
		if (totaln != totalm) return false;
		for (int i = 0; i < sn.length()-1; i++){
			sm = sm.charAt(sm.length() - 1) + sm.substring(0, sm.length() - 1);
			if (sm.equals(sn)) return true;
		}
		return false;
	}
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {
	static BufferedReader br;
	static PrintWriter pw;
	static StringTokenizer st;
	static int k, ch, chmp, btmp, bchmp = 0;
	static int n, tmp;
	static String str, ch1, ch2;
	static String[] stray = new String[2];
	static int[] intray = new int[2];
	static String[] copy = new String[2000001];

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(br.readLine());
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	char nextChar() throws IOException {
		return (char) br.read();
	}

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new FileReader("input.in"));
		pw = new PrintWriter("output.out");

		n = Integer.parseInt(br.readLine());

		for (int i = 1; i <= n; i++) {
			str = br.readLine();
			st = new StringTokenizer(str, " \t\n\r,.");
			while (st.hasMoreTokens()) {
				stray[k] = st.nextToken();
				k++;
			}

			for (int j = 0; j < 2; j++) {
				intray[j] = Integer.parseInt(stray[j]);
			}

			for (int j = intray[0]; j < intray[1] - 1; j++) {
				for (int p = j + 1; p <= intray[1]; p++) {
					ch1 = Integer.toString(j);
					ch2 = Integer.toString(p);
					if (ch1.length() != ch2.length()) {
						continue;
					}
					tmp = ch1.length();
					for (int k1 = 0; k1 < tmp; k1++) {
						ch1 = ch1.charAt(tmp - 1) + ch1;
						for (int k2 = 0; k2 < tmp; k2++) {
							if (ch1.charAt(k2) == ch2.charAt(k2)) {
								chmp++;
							} else {
								break;
							}
						}
						if (chmp == tmp) {
							for (int j1 = 0; j1 < btmp; j1++) {
								bchmp = 0;
								for (int k2 = 0; k2 < tmp; k2++) {
									if (ch1.charAt(k2) == copy[j1].charAt(k2)) {
										bchmp++;
									} else {
										continue;
									}
								}
							}

							if (bchmp == tmp) {
								chmp = 0;
								break;
							}

							str = "";
							for (int j1 = 0; j1 < tmp; j1++) {
								str += ch1.charAt(j1);
							}
							copy[btmp] = str;
							btmp++;
							ch++;
						}
						chmp = 0;
					}
					bchmp = 0;
				}
			}
			btmp = 0;
			pw.println("Case #" + i + ": " + ch);
			ch = 0;
			k = 0;
		}

		br.close();
		pw.close();
	}
}