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);
	}
}

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Scanner;

public class recycle {

	public static HashMap<String, String> bigmap = new HashMap<String, String>();

	public static void main(String[] args) throws FileNotFoundException {
		File f = new File("in.in");
		Scanner input = new Scanner(f);
		int k = Integer.parseInt(input.nextLine());
		for (int i = 0; i < k; i++) {
			String[] stuff = input.nextLine().split(" ");
			int a = Integer.parseInt(stuff[0]);
			int b = Integer.parseInt(stuff[1]);
			System.out.println("Case #" + (i + 1) + ": " + doit(a, b));
		}
	}

	public static int doit(int A, int B) {

		HashMap<String, String> m = new HashMap<String, String>();
		int n = 1;
		for (int a = A; a < B; a++) {
			for (int b = a + 1; b <= B; b+=n) {
				n = 1;
				if (bigmap.containsKey(a + "" + b)) {
					m.put(a + "" + b, "");
				} else {
					String s = a + "";
					String q = b + "";
					for (int i = 0; i < s.length(); i++) {
						String old = s;
						char c = s.charAt(s.length() - 1);
						s = c + s.substring(0, s.length() - 1);
						if (s.equals(q)) {
							n = 9;
							m.put(a + "" + b, "");
							bigmap.put(a + "" + b, "");
						}
					}
				}
			}
		}
		return m.size();
	}

}
