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

public class C {
	private int[] tens = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};
	public static void main(String[] args) {
		C c = new C();
		c.solve();
	}
	
	public void solve() {
		Scanner in = new Scanner(System.in);
		int t = in.nextInt();
		for(int ii = 1; ii <= t; ++ii) {
			int a = in.nextInt();
			int b = in.nextInt();
			long total = 0;
			for(int check = a; check < b; ++check) {
				total += countRecycle(check, b);
			}
			System.out.printf("Case #%d: %d\n", ii, total);
		}
	}
	
	public int countRecycle(int num, int max) {
		int size = getSize(num); //12345, size = 4, 10000, size = 4, 9999, size = 3
		HashSet<Integer> valid = new HashSet<Integer>();
		for(int i = 1; tens[i] <= num; ++i) {
			int newNum = (num/tens[i]) + (num%tens[i])*(tens[size-i+1]);
			if(newNum <= max && newNum > num)
				valid.add(newNum);
		}
		return valid.size();
	}
	
	public int getSize(int a) {
		int size = 0;
		while(tens[size] <= a)
			++size;
		return size - 1;
	}
}