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

			}
		}

	}
}

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;

public class C_RecycledNumbers {
	static int a;
	static int b;
	static HashSet<String> set;

	public static void main(String[] args) throws FileNotFoundException {
		Scanner sc = new Scanner(new File("C2in.txt"));
		PrintWriter writer = new PrintWriter(new File("C2out.txt"));
		int t = sc.nextInt();
		for (int i = 1; i <= t; i++) {
			a = sc.nextInt();
			b = sc.nextInt();
			int count = 0;
			set = new HashSet<String>();
			for (int j = a; j <= b; j++) {
				count += get(j);
			}
			writer.println("Case #" + i + ": " + count / 2);
			
		}
		
		writer.close();
	}

	private static int get(int j) {
		String s = j + "";
		int n = s.length();
		int count = 0;
		HashSet<Integer> set1 = new HashSet<Integer>();
		for (int i = 0; i < n - 1; i++) {
			String ss = s.substring(1) + s.charAt(0) + "";
			s = ss;
			int x = Integer.parseInt(ss);

			if (x >= a && x <= b && s.charAt(0) != '0' && !set1.contains(x)) {
				if (j != x) {
					set1.add(x);
					count++;
				}
			}
		}
		return count;
	}
}
