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.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;

public class ProblemC {
	public static void main(String[] args) throws Exception {

		Scanner in = new Scanner(//
				// System.in
//				new FileInputStream("c-small.in")
		 new FileInputStream("c-large.in")
		);
		PrintStream out = new PrintStream( //
				// System.out
//				new FileOutputStream("c-small.out")
		 new FileOutputStream("c-large.out")
		);

		int T = in.nextInt();
		for (int i = 1; i <= T; i++) {
			int A = in.nextInt();
			int B = in.nextInt();
			int res = 0;
			for (int x = A; x < B; x++) {
				res += cycle(x, A, B);
			}
			out.println("Case #" + i + ": " + res);
		}
	}

	private static int cycle(int n, int A, int B) {
		int m = n;
		int digits = (int) Math.log10(n) + 1;
		if (digits == 1)
			return 0;
		int mul = 1;
		for (int i = 1; i < digits; i++)
			mul *= 10;
		int ret = 0;
		HashSet<Integer> used = new HashSet<Integer>();
		for (int i = 0; i < digits; i++) {
			m = (m / 10) + (m % 10) * mul;
			if (m > n && m != n && m <= B && !used.contains(m)) {
				ret++;
				used.add(m);
			}
		}
		return ret;
	}

}
