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.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


public class Task3 {
	private int parseLine(Scanner scanner) throws IOException {
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int c = ("" + A).length();
		int pow = (int) Math.pow(10, c - 1);
		int count = 0;
		for (int m = A; m < B; m++) {
			int tmpN = m;
			Set<Integer> set = new HashSet<Integer>();
			for (int j = 0; j < c - 1; j++) {
				tmpN = tmpN / 10 + (tmpN % 10) * pow;
				if (m < tmpN && tmpN <= B && !set.contains(tmpN)) {
					set.add(tmpN);
					count++;
				}
			}
		}
		return count;
	}
	
	public void run(Scanner scanner, Writer bw) throws IOException {
		int rowCnt = scanner.nextInt();
		for (int i = 0; i < rowCnt; i++) {
			bw.write("Case #" + (i + 1) + ": " + parseLine(scanner) + '\n');
		}
		bw.flush();
		bw.close();
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Scanner scanner = new Scanner(System.in);
			scanner.useDelimiter(" |\r\n|\n|\r");
			new Task3().run(new Scanner(System.in),
					new OutputStreamWriter(System.out));
		} catch (IOException e) {
			return;
		}
	}
}
