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

import java.util.HashSet;

/**
 *
 * @author vandit
 */
public class RecycleNumbers {

    private HashSet<String> numbers = new HashSet<String>();
    private HashSet<String> initialTempNumbers = new HashSet<String>();
    private HashSet<String> finalTempNumbers = new HashSet<String>();

    HashSet<Pair> numberPairs = new HashSet<Pair>();


    private void findRecycledNumbers(int start, int end, int places) {


        for (int i = start; i <= end; i++) {
            String initialNumber = Integer.toString(i);
            //if (!(numbers.contains(initialNumber) || finalTempNumbers.contains(initialNumber))) {

                StringBuffer tempNumber = new StringBuffer(initialNumber);
                int len = tempNumber.length();
                int startIndexToMove = len - places;
                String tempString = tempNumber.substring(startIndexToMove);
                if ((places == 1 && tempString.equals("0")) || tempString.charAt(0) == '0') {
                    continue;
                }
                tempNumber.delete(startIndexToMove, len);
                String finalTempNumber = tempString + tempNumber.toString();

                if (! (finalTempNumber.equals(initialNumber) || Integer.parseInt(finalTempNumber) > end || Integer.parseInt(finalTempNumber) < Integer.parseInt(initialNumber))) {
                    numbers.add(initialNumber);
                    finalTempNumbers.add(finalTempNumber);
                    Pair pair = new Pair(finalTempNumber,initialNumber);
                    numberPairs.add(pair);
                }
            }

        

    }

    public HashSet<Pair> findAllRecycledNumbers(int start, int end) {
        int length = Integer.toString(start).length();
        for (int i = 1; i < length; i++) {
            findRecycledNumbers(start, end, i);
        }
        return numberPairs;
    }
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;


public class recycled {
	private static File f = new File("C:/Users/Cybermask/Desktop/myfile.txt");
	private static File outfile = new File("C:/Users/Cybermask/Desktop/out.txt");
	private static BufferedReader reader;

	private static String read() throws Exception{
		return reader.readLine();
	}
	private static int toint(String s){
		return Integer.parseInt(s);
	}
	private static ArrayList<Object> reverse(ArrayList<Object>list){
		ArrayList<Object> result = new ArrayList<Object>();
		for(int i=0;i<list.size();i++)
			result.add(list.get(list.size()-i-1));
		return result;
		
	}
public static void main(String args[])throws Exception{
	reader = new BufferedReader(new FileReader(f));
	PrintWriter pw = new PrintWriter(outfile);
	int n = toint(read());
	for(int i = 0 ; i<n;i++){
		String string = read();
		Scanner s = new Scanner(string);
		s.useDelimiter(" ");
		int f = s.nextInt();
		int l = s.nextInt();
		int count = 0 ;
		pw.print("Case #"+(i+1)+": ");
	
		for(int k=f;k<=l;k++){
			String number = k+"";
			int first = toint(number);
			HashSet<Integer> hs = new HashSet<Integer>();
			for(int o=1;o<number.length();o++){
				
				String 	number2=number.substring(number.length()-o,number.length())+""+number.substring(0,number.length()-o);
				
		
				
				int result = toint(number2);
				if(number.length()==number2.length() &&result>=f && result<=l && result > first){
					hs.add(result);
				}
				
			}
			count+=hs.size();
		}
		pw.println(count);
		
		
	}
	pw.flush();
}
}