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();
	}

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package googlecodejamqualifier;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

/**
 *
 * @author Dean
 */
public class RecycledNumbers {

    public static void main(String args[]) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int testCases = Integer.parseInt(reader.readLine().trim());
        for (int i = 0; i < testCases; i++) {
            String split[] = reader.readLine().split("[\\s]+");
            int A = Integer.parseInt(split[0]);
            int B = Integer.parseInt(split[1]);
            System.out.println("Case #" + (i + 1) + ": " + countPermutations(A, B));
        }
    }

    public static int countPermutations(int A, int B) {
        int pow[] = new int[] {1,10,100,1000,10000,100000,1000000,10000000};
        int count = 0;

        int digits = (B + "").length();
        for (int m = A + 1; m <= B; m++) {
            HashMap<Integer, Boolean> checked = new HashMap<Integer, Boolean>(10);
            for (int i = 1; i < digits; i++) {
                int mul = (int) (Math.pow(10, i));
                int move = m % mul;
                int n = m / mul;
                n = n + move * (int) (Math.pow(10, (digits - i)));
                if ((n < m) && ((n + "").length() == digits)&& (A <= n)) {
                    //count++;
                    if (checked.containsKey(n)) {
                        continue;
                    } else {
                        count++;
                        checked.put(n, true);
                    }
                }
            }
        }
        return count;
    }
}
