import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

package codejam2012;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class QualC {
	public static void main(String[] args) throws FileNotFoundException {
		Scanner in = new Scanner(new FileInputStream(new File("/home/rush/sample-in.txt")));
		PrintWriter out = new PrintWriter(new FileOutputStream("/home/rush/sample-out.txt"));
		
//		Scanner in = new Scanner(System.in);
//		PrintWriter out = new PrintWriter(System.out);
		int t = in.nextInt();
		
		
		Map<Integer, Integer> count = new HashMap<Integer, Integer>();
		for (int i = 0; i < t; i++) {
			int total = 0;
			
			int s = in.nextInt();
			int e = in.nextInt();
			
			for (int j = s; j <= e; j++) {
				if (count.containsKey(j)) {
					total += count.get(j);
					continue;
				}
				
				String num = j + "";
				int cnt = 0;
				Map<Integer, Boolean> map = new HashMap<Integer, Boolean>();
				for (int k = 1; k < num.length(); k++) {
					String pre = num.substring(0, k);
					String post = num.substring(k);
					String tnum = post + pre;
					int tn = Integer.parseInt(tnum);
					if (j < tn && tn <= e && !map.containsKey(tn)) {
						cnt++;
						total++;
						map.put(tn, true);
					}
				}
				count.put(j, cnt);
			}
			
			out.printf("Case #%d: %d", (i+1), total);
			out.println();
		}
		out.flush();
	}
}
