package codejam;

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

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

/**
 * 
 */

/**
 * @author Mostafa
 *
 */
public class RecycledNumbers {
	
	public static String traverse(String x) {
		char[] m = x.toCharArray();
		m[0] = x.charAt(1);
		m[1] = x.charAt(0);
		String t = new String(m);
		return t;
	}
	
	public static String traverse1(String x) {
		char[] m = x.toCharArray();
		m[0] = x.charAt(2);
		m[1] = x.charAt(0);
		m[2] = x.charAt(1);
		String t = new String(m);
		return t;
	}
	public static String traverse2(String x) {
		char[] m = x.toCharArray();
		m[0] = x.charAt(1);
		m[1] = x.charAt(2);
		m[2] = x.charAt(0);
		String t = new String(m);
		return t;
	}
	
	public static int renumber(int first, int last) {
		String[] test = new String[last-first+1];
		int i, j;
		int testc = 0;
		int count = 0;
		for (i = first; i<=last; i++) {
			String x = Integer.toString(i);
			test[testc] = x;
			testc++;
		}
		if (test[0].length() == 1) {
			count = 0;
		}
		else if (test[0].length() == 2) {
			for (i=0; i<test.length; i++) {
				for (j = i+1; j<test.length; j++) {
					if (test[i].compareTo(traverse(test[j])) == 0) {
						count++;
					}
				}
			}
		}
		else if (test[0].length() == 3) {
			for (i=0; i<test.length; i++) {
				for (j = i+1; j<test.length; j++) {
					if (test[i].compareTo(traverse1(test[j])) == 0) {
						count++;
					}
					if ((test[i].compareTo(traverse2(test[j])) == 0)) {
						count++;
					}
				}
			}
		}
		return count;
	}
}
