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 Java{

	public static void main(String[] args) {
		try {
			BufferedReader in = new BufferedReader(new FileReader("C-large.in"));
			int cases = Integer.parseInt(in.readLine());
			for (int i = 1; i <= cases; i ++){
				String[] temp = (in.readLine()).split(" ");
				int A = Integer.parseInt(temp[0]);
				int B = Integer.parseInt(temp[1]);
				logic(A, B, i);
			}
			in.close();
		} catch (IOException e) {
			System.out.println("INPUT ERROR");
		}
	}

	public static void logic(int A, int B, int caseNum){
		int num = A, result = 0;
		while (num < B){
			int factor = 10;
			int toFront = num%factor;
			int toBack = num/factor;
			int prev = -1;
			while (toFront < num){
				int x = Integer.parseInt(toFront+""+toBack);
				if (x > num && x <= B && x != prev){
					result ++;
					prev = x;
				}
				factor *= 10;
				toFront = num%factor;
				toBack = num/factor;
			}
			num ++;
		}
		System.out.println("Case #" + caseNum + ": " + result);
	}
}