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

package recycled;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.TreeSet;

/**
 *
 * @author Alfred
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    try {
            FileInputStream fstream = new FileInputStream("C-small-attempt0.in");
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            FileWriter outFile = new FileWriter("out.txt");
            PrintWriter out = new PrintWriter(outFile);
            String line;
            line = br.readLine();
            int cases = Integer.parseInt(line);
            for (int i=1; i<=cases;i++){
                line = br.readLine();
                String[] values = line.split(" ");
                int A = Integer.parseInt(values[0]);
                int B = Integer.parseInt(values[1]);
                int total=0;
                for (int n=A; n<=B;n++){
                    TreeSet<String> solutions = new TreeSet<String>();
                    for (int k=1;k<values[1].length();k++){
                        String m = circshift(n,k);
                        int mVal = Integer.parseInt(m);
                        if(mVal<=B && mVal!=n  && mVal> n && !m.startsWith("0") && m.length()==Integer.toString(n).length() )
                        {
                            solutions.add(m);
                        }                   
                    }
                    total+=solutions.size();
                }
                out.println("Case #"+i+": "+total);
            }
            in.close();
            out.close();
        } catch (Exception e) {//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }

}

    private static String circshift(int n, int k) {
        String nString=Integer.toString(n);
        int len=nString.length();
        String m =  nString.substring(len-k)+nString.subSequence(0, len-k);
        //System.out.println(n+" "+m);
        return m;
    }

}

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;


public class C {

	public static ArrayList<String> toArray(String number){
		ArrayList<String> array = new ArrayList<String>();	
		char[] numbers = number.toCharArray();
		
		for (int i=0; i<number.length(); i++)
			array.add(new String(numbers[i]+""));

		return array;
	}
	
	
	public static boolean isPossible(ArrayList<String> array1, ArrayList<String> array2){
		String number1="";
		String number2="";
	
		for (int i=0; i<array1.size(); i++)
			number1 = number1.concat(array1.get(i).toString());
		
		int n1 = Integer.parseInt(number1);
				
		for (int j=0; j<array2.size(); j++){
			number2="";
			for (int m=0; m<array2.size(); m++)
				number2 = number2.concat(array2.get(m).toString());

			if (!number2.startsWith("0")){
				int n2 = Integer.parseInt(number2);
	
				if (n1 == n2)
					return true;
			}
			
			String lastElement = array2.get(array2.size()-1);
			array2.add(0, lastElement);
			array2.remove(array2.size()-1);
		}
		
		return false;
	}
	
	
	
	public static void main(String[] args) throws IOException  {
		Scanner in = new Scanner(new FileReader("C-small-attempt5.in"));
		FileWriter output = new FileWriter("C-small-output.txt");
		String line = in.nextLine();
		ArrayList<String> array1;
		ArrayList<String> array2;
		String number1, number2;
		int n = Integer.parseInt(line);
		int pairs, n1, n2;

		for (int i = 0; i < n; i++) {
			n1 = in.nextInt();
			n2 = in.nextInt();
			pairs = 0;

			for (int j=n1; j<n2; j++){
				number1 = String.valueOf(j);
				
				for (int k=j+1; k<=n2; k++){
					number2 = String.valueOf(k);	
					array1 = toArray(number1);
					array2 = toArray(number2);
					
					if (isPossible(array1, array2))
						pairs++;
				}
			}
			
			output.write("Case #" + (int) (i+1) +": " + pairs + "\n");
		}
		
		output.close();
	}
}
