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.util.HashSet;

public class CSolver extends SolverModule {

	@Override
	String processLine(String line) {
		int[] lines = toIntegers(line.split(" "));
		int A = lines[0];
		int B = lines[1];
		HashSet<String> hashSet = new HashSet<String>();
		for (int i = A; i < B; i++) {
			int length = String.valueOf(A).length();
			for (int j = 1; j < length; j++) {
				int a = rightMove(i, length - j);
				int b = leftMove(i, j)
						- leftMove(rightMove(i, (length - j)), length);
				int total = a + b;
				if (total >= A && total <= B && total > i) {
					hashSet.add(i + "," + total);
				}
			}
		}
		return String.valueOf(hashSet.size());
	}

	private int leftMove(int number, int count) {
		number = number * (int) (Math.pow(10, count));
		return number;
	}

	private int rightMove(int number, int count) {
		if (count == 0) {
			return number;
		}
		number = (number / (int) (Math.pow(10, count)));
		return number;
	}
}
