package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}

import java.util.*;

public class RecycledNumbers
{
	static class Number implements Comparable<Number> {
		int[] digits;
		public Number(String str) {
			digits = new int[str.length()];
			for(int i=0;i<digits.length;i++)
				digits[i] = str.charAt(i) - '0';
		}
		public Number(Number old, int shift) {
			digits = new int[old.digits.length];
			for(int i=0;i+shift < digits.length;i++)
				digits[i] = old.digits[i+shift];
			for(int i=0;i<shift;i++)
				digits[digits.length - shift + i] = old.digits[i];
		}
		boolean isValid() {
			return digits[0] != 0;
		}
		public int compareTo(Number other) {
			if (digits.length != other.digits.length)
				return digits.length - other.digits.length;
			for (int i=0;i<digits.length;i++) {
				if (digits[i] != other.digits[i])
					return digits[i] - other.digits[i];
			}
			return 0;
		}
	}
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args)
	{
		int T = sc.nextInt();
		for(int i=1;i<=T;i++)
		{
			System.out.println("Case #"+i+": "+solveCase());
		}
	}
	static String solveCase()
	{
		int lower = sc.nextInt(); Number lowerNum = new Number(""+lower);
		int upper = sc.nextInt(); Number upperNum = new Number(""+upper);
		int res = 0;
		for(int i=lower; i<= upper; i++) {
			Number num = new Number(""+i);
			for(int j=1;j<num.digits.length;j++) {
				Number shift = new Number(num, j);
				if (num.compareTo(shift) == 0)
					break;
				if (num.compareTo(shift) < 0 && shift.compareTo(upperNum) <= 0) {
					res++;
				}
			}
		}
		return "" + res;
	}
}
