/*
 * 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.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashSet;


public class RecycledNumbers {
	public static void main(String[] args) throws Exception {
		String sb = null;
		int ans = 0;
		
		BufferedReader is = new BufferedReader(new FileReader(new File("D:\\C-small-attempt0.in")));		
		BufferedWriter os = new BufferedWriter(new FileWriter("D:\\out.txt"));
		os.flush();
		HashSet<String> hs = null;
		int loopIter = Integer.parseInt(is.readLine());
		
		for(int i=0; i<loopIter; i++){
			sb = is.readLine();
			ans = 0;
			hs = new HashSet<String>();
			String x[] = sb.split(" ");
			int start = Integer.parseInt(x[0]);
			int end = Integer.parseInt(x[1]);
			
			for(int j=start; j<=end; j++){
				String h = j + "";
				for(int k=0; k<h.length(); k++){
					h = h.substring(1) + h.substring(0,1);
					int xxx = Integer.parseInt(h);
					if(xxx != j && xxx>= start && xxx <= end){
						//System.out.println("start = " + start + ", end = " + end + ", j = " + j + ", reverse = " + h);
						hs.add("(" + j + "," + h + ")");
						ans++;
					}
				}
			}
			

			if(ans %2 != 0){
				System.out.println("FUCKED! = " + sb);			
			}

			
			os.write("Case #" + (i+1) + ": " + hs.size()/2 + "\n");
			os.flush();
		}
		
		
		
	}
}
