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 C_RecycledNumbers {
	static String name = "C-large";
	static boolean been[];

	static int f(int a, int b) {
		//System.out.println(a + " " + b);
		been[a] = true;
		int c = a;
		int num = 1, k = -1, ans = 1;
		while (c != 0) {
			c /= 10;
			num *= 10;
			k++;
		}
		num /= 10;
		c = a;
		for (int i = 0; i < k; i++) {
			int rem = a % 10;
			a /= 10;
			a += rem * num;
			if (a <= b && a >= c) {
				if (been[a])
					continue;
//				System.out.println(a+" "+c);
				been[a] = true;
				ans++;
			}
		}
		return ans * (ans - 1) / 2;

	}

	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader(name + ".in"));
		PrintWriter out = new PrintWriter(name + ".out");
		int t = Integer.parseInt(in.readLine()), caseN = 1;
		been = new boolean[10000000];
		while (caseN <= t) {
			long ans = 0;
			StringTokenizer tok = new StringTokenizer(in.readLine());

			int a = Integer.parseInt(tok.nextToken()), b = Integer.parseInt(tok
					.nextToken());
			for (int i = a; i <= b; i++) {
				ans += f(i, b);
			}
			Arrays.fill(been, a, b + 10, false);

			out.print("Case #");
			out.print(caseN++);
			out.print(": ");
			out.println(ans);
		}
		out.flush();
	}
}
