package fixjava;

public class StringUtils {

	/** Repeat the given string the requested number of times. */
	public static String repeat(String str, int numTimes) {
		StringBuilder buf = new StringBuilder(Math.max(0, str.length() * numTimes));
		for (int i = 0; i < numTimes; i++)
			buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the left hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padLeft(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(padChar);
		for (int i = 1, mi = bufSize - str.length(); i < mi; i++)
			buf.append(padChar);
		buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the right hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padRight(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(str);
		buf.append(padChar);
		while (buf.length() < bufSize)
			buf.append(padChar);
		return buf.toString();
	}

	/** Intern all strings in an array, skipping null elements. */
	public static String[] intern(String[] arr) {
		for (int i = 0; i < arr.length; i++)
			arr[i] = arr[i].intern();
		return arr;
	}

	/** Intern a string, ignoring null */
	public static String intern(String str) {
		return str == null ? null : str.intern();
	}

}

import java.io.*;
import java.util.*;

public class clarge {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		int[][] list = new int[2000000][];


		for (int i=0; i<2000000; i++) {
			list[i] = fill(i);
		}

		int numCases = stdin.nextInt();

		for (int loop=1; loop<=numCases; loop++) {

			int A = stdin.nextInt();
			int B = stdin.nextInt();

			int sum = 0;
			for (int i=A; i<=B; i++) {

				if (list[i] != null) {
					for (int j=0; j<list[i].length; j++)
						if (list[i][j] <= B)
							sum++;
				}

			}
			System.out.println("Case #"+loop+": "+sum);
		}

	}

	public static int[] fill(int val) {

		if (val < 10) return null;

		int[] temp = new int[7];

		int index = 0;

		int saveval = val;

		int numdigits = numd(val);

		for (int i=0; i<numdigits; i++) {

			val = rotate(saveval, val, numdigits);

			if (val > saveval) {
				temp[index] = val;
				index++;
			}
		}

		int[] ans = new int[index];
		for (int i=0; i<index; i++)
			ans[i] = temp[i];

		return ans;

	}

	public static int rotate(int orig, int val, int numd) {
		return (val%10)*pow10(orig) + val/10;
	}

	public static int pow10(int val) {

		if (val == 0) return 0;

		int cnt = 1;
		while (val >= 10) {

			cnt*=10;
			val /= 10;
		}
		return cnt;
	}

	public static int numd(int val) {

		if (val == 0) return 0;

		int cnt = 0;
		while (val > 0) {

			cnt++;
			val /= 10;
		}
		return cnt;
	}
}
