import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

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

/**
 *
 * @author binny
 */
import java.io.*;
import java.util.ArrayList;


public class RecycledNumber {


    public static void main(String args[]) throws Exception {
        String inputPath = "//C-small-attempt0.in";
        String outputPath = "//C-small-attempt0.out";

        RecycledNumber rw = new RecycledNumber();
        String[] str = rw.readFromFile(inputPath);
        String[] solution = getSolution(str);
        rw.writeToFile(outputPath, solution);
    }

    private static String[] getSolution(String[] str) {
        int noOftestCases = Integer.parseInt(str[0]);
        String[] output = new String[noOftestCases];
        for (int i = 1; i <= noOftestCases; i++) {
            String[] arr = str[i].split(" ");
            int lowerLimit = Integer.parseInt(arr[0]);
            int upperLimit = Integer.parseInt(arr[1]);
            int count = 0;
            while (upperLimit > lowerLimit) {
                for (int j = 0; j < upperLimit - lowerLimit; j++) {
                    count = count + isRecycledPossible(String.valueOf(lowerLimit + j), String.valueOf(upperLimit));
                }
                upperLimit--;
            }
            output[i - 1] = "Case #" + i + ": " + count;
        }
        return output;
    }

    public static int isRecycledPossible(String a, String b) {

        int countInRecycledPossible = 0;
        for (int i = 0; i < a.length(); i++) {
            for (int j = i; j < a.length(); j++) {
                if (Integer.parseInt(rotate(a,j)) - Integer.parseInt(b) == 0) {
                    countInRecycledPossible++;
                    break;
                }
            }
            if(countInRecycledPossible>0){
             break;
            }
        }
        return countInRecycledPossible;
    }

    public static String rotate(String a, int i) {
        String substring = a.substring(a.length() - i);
        String rotatedDigit = substring + a.substring(0,a.length() - i);
        return rotatedDigit;
    }

    public String[] readFromFile(String inputPath) throws FileNotFoundException, IOException {
        FileInputStream fis = null;
        DataInputStream dis = null;
        BufferedReader br = null;
        ArrayList<String> strArrList = new ArrayList<String>();
        try {
            fis = new FileInputStream(inputPath);
            dis = new DataInputStream(fis);
            br = new BufferedReader(new InputStreamReader(dis));
            String strLine;
            while ((strLine = br.readLine()) != null) {
                strArrList.add(strLine);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
                if (dis != null) {
                    dis.close();
                }
                if (fis != null) {
                    fis.close();
                }
            } catch (IOException e) {
                e.printStackTrace();

            }
        }
        return strArrList.toArray(new String[strArrList.size()]);
    }

    public void writeToFile(String outputPath, String[] strArr) {
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter(outputPath));

            for (int i = 0; i < strArr.length; i++) {
                bw.write(strArr[i]);
                bw.newLine();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bw != null) {
                    bw.flush();
                    bw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
