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.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;

public class C {
	public static int factorial(int x) {

		int fact = 1;

		for (int i = 2; i <= x; i++) {

			fact *= i;

		}
		return fact;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
//		Scanner s = null;
//		try {
//			s = new Scanner(new FileInputStream("s.in"));
//		} catch (FileNotFoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		int lines = s.nextInt();
		for (int i = 1 ; i <= lines ;i++){
			int A = s.nextInt();
			int B = s.nextInt();
			HashSet<Integer> h = new HashSet<Integer>();
			for (int j  = A;j<=B;j++){
				h.add(j);
			}
			
			int comb = 0;
			for (int j  = A;j<=B;j++){
				if (!h.remove(j)){
					continue;
				}
				int len = (int)Math.log10(j);
				int c = 1;
				int newj = j;
				for (int k = 0; k < len;k++){
					newj = newj/10 + (newj % 10)*((int)Math.pow(10, len));
					if (h.remove(newj)){
						
						c++;
					}
				}
				if (c !=1){
					comb += factorial(c)/(factorial(c-2)*2);
				}
				
			}
			System.out.printf("Case #%d: %d\n",i,comb);
		}
	}
}
