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

public class Recycled {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int t = Integer.parseInt(br.readLine());
            for (int i = 0; i < t; i++) {
                String[] str = br.readLine().split(" ");
                int a = Integer.parseInt(str[0]);
                int b = Integer.parseInt(str[1]);
                System.out.println("Case #" + (i + 1) + ": " + find(a, b));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int find(int a, int b) {
        HashSet<Long> used = new HashSet<Long>();
        int digits = String.valueOf(a).length();
        if (digits == 1) return 0;
        for (int i = a; i <= b; i++) {
            int s = 10;
            int m = (int) Math.pow(10, digits-1);
            for (int j = 0; j < digits-1; j++) {
                int r = i % s;
                if (r < s/10) continue;
                int q = i / s;
                int rn = r * m + q;
                s *= 10; m /= 10;
                if (i != rn && rn >= a && rn <= b) {
                    long pp;
                    if (rn < i) pp = (long)rn << 30 | i;
                    else pp = (long)i << 30 | rn;
                    if (!used.contains(pp)) {
                        used.add(pp);
                    }
                }
            }
        }
        return used.size();
    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;



public class RecycledNumbers{
	public static void main(String[] args) throws IOException{
		String testCases;
		BufferedReader brTestCases = new BufferedReader(new InputStreamReader(System.in));
		File inFile = new File("C:/Users/AbhilashR/Downloads/C-large.in" ); 
		Scanner sc = new Scanner(inFile);
		//testCases = (String)brTestCases.readLine();
		testCases = sc.nextLine();
		Integer noOfTestCases = null;
		try{
			noOfTestCases = Integer.parseInt(testCases);
		}catch (NumberFormatException e){
			System.out.println("The entered value is not a Number");
		}
		ArrayList<String> inputData = new ArrayList<String>();
		for(int i =0;i<noOfTestCases;i++){
			brTestCases = new BufferedReader(new InputStreamReader(System.in));
			//testCases = (String)brTestCases.readLine();
			testCases = sc.nextLine();
			inputData.add(testCases);
		}
		
		ArrayList<Object[]> inputDataObj = new ArrayList<Object[]>();
		for(int i =0;i<inputData.size();i++){
			inputDataObj.add(inputData.get(i).split(" "));
		}
		Writer output = null;
		File outFile = new File("C:/Users/AbhilashR/Downloads/outPut.txt" );
		output = new BufferedWriter(new FileWriter(outFile));
		String text = "";
		for(int i =0;i < inputDataObj.size();i++){
			Object[] dataObj = inputDataObj.get(i);
			int integerA = Integer.parseInt((String)dataObj[0]);
			int integerB = Integer.parseInt((String)dataObj[1]);
			int recycledNumbers = getRecycledNumbers(integerA, integerB);
			text = "Case #"+(i+1)+": "+recycledNumbers+"\r\n";
			output.write(text);
			output.flush();
			
		}
		//output.write(text);
		output.close();
	}
	public static Integer getRecycledNumbers(Integer a,Integer b){
		Integer noOfRecycledNumbers = 0;
		Integer sampleN =a;
		
		Integer numberOfDigits = 0;
		numberOfDigits = Integer.toString(a).length();
		for(sampleN =a; sampleN < b ;sampleN++){
			Integer sampleM = sampleN;
			Set<Integer> tempSet = new HashSet<Integer>();
			for(int j =0; j< numberOfDigits; j++){
				int currentSize = Integer.toString(sampleM).length();
				if(currentSize==numberOfDigits){
					sampleM = Integer.parseInt(Integer.toString(sampleM%10)+Integer.toString(sampleM/10));
				}else{
					String formingSampleM = Integer.toString(sampleM%10);
					for(int k =0;k<numberOfDigits-currentSize;k++){
						formingSampleM = formingSampleM+"0";
					}
					formingSampleM = formingSampleM+Integer.toString(sampleM/10);
					sampleM = Integer.parseInt(formingSampleM);
				}
				if(sampleN<sampleM && sampleM<=b){
					tempSet.add(sampleM);
				}
			}	
			noOfRecycledNumbers += tempSet.size();
		}
		if(noOfRecycledNumbers>0){
			return noOfRecycledNumbers;
		}
		return 0;
	}
	
}