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

}

package taskc;

import java.io.FileNotFoundException;
import java.util.*;
import java.io.File;
import java.io.PrintWriter;

public class TaskC {
    
    private long[] tenPowers = new long[10];
    private long[]prevPairs = new long[10];
    private void prepareTenPowers(){
        tenPowers[0] = 1;
        for(int i = 1;i<10;i++){
            tenPowers[i]=tenPowers[i-1]*10;
        }
    }
    
    private void solve(Scanner in, PrintWriter out, int caseNum){
        long res = 0;
        long A = in.nextInt();
        int B = in.nextInt();
        for(long t = A;t<=B;t++){
            long d = t;
            int aPow = 0;
            while(d>0){
                aPow++;
                d = d/10;
            }
            long pow = 10;
            d = t/10;
            int k = 1;
            int pairsCnt = 0;
            
            while(d>0){
                long rest = t%pow;
                if(rest!=0){
                    long pair = rest*tenPowers[aPow-k]+ d;
                    if((pair>t)&&(pair<=B)){
                        boolean ok = true;
                        check:
                        for(int i = 0;i<pairsCnt;i++){
                            if(prevPairs[i]==pair){
                                ok = false;
                                break check;
                            }
                        }
                        if(ok){
                          //System.out.println(t + " " + pair);
                            res++;
                            prevPairs[pairsCnt] = pair;
                            pairsCnt++;
                        }
                    }
                }
                k++;
                pow*=10;
                d /=10;
            }
        }
        out.format("Case #%d: %s\n", caseNum, res);
    }

    public TaskC(){
        prepareTenPowers();
        try{
            Scanner in = new Scanner(new File("C-large.in"));
            int T = in.nextInt();
            PrintWriter out = new PrintWriter("Clarge.out");
            for(int i = 0;i<T;i++){
                solve(in,out,i+1);
            }
            out.close();
        } catch (FileNotFoundException e){
            System.out.println("File not found");
        }
        
    }
    public static void main(String[] args) {
        TaskC instance = new TaskC();
    }
}
