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


public class Recycle {

	private static int[] total(int r)	{
		int i=1, t=10;
		while(r/t > 0)	{
			i++;
			t*=10;
		}
		return new int[] {i,t/10};
	}
	
	private static int pow(int c)	{
		int t=1;
		while(c-->0)
			t*=10;
		return t;
	}
	
	private static int recycle(int r, int c /* peechhe se, 1 based*/)	{
		int k = pow(c), t=total(r)[0];
		int a = r/k;
		int b = (r%k) * pow(t-c);
		return a+b;
	}
	
	public static void main(String[] args) {
		Scanner c = new Scanner(System.in);
		int t = c.nextInt();
		for(int w=1; w<=t; ++w)	{
			System.out.print("Case #"+w+": ");
			int cnt = 0;
			int A = c.nextInt();
			int B = c.nextInt();
			int tmp[] = total(A);
			int tot = tmp[0];
			
			for(int i=Math.max(A, 10); i <=B; ++i )	{
				int in = i/tmp[1];
				int pow = 1;
				LinkedList<Integer> l = new LinkedList<Integer>();
				for(int j=1; j<tot; ++j, pow*=10)	{
					int cth = (i/pow)%10;
					
					if(cth >= in)	{
						int r = recycle(i,j);
						if(r > i && r<=B && !l.contains(r))	{
							cnt++;
							l.add(r);
							//System.out.println("("+i+","+r+")");
						}
					}
				}
			}
			System.out.println(cnt);
		}

	}

}
