package codejam;

import java.util.*;
import java.io.*;

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

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

package google_jamp_c;
import java.io.*;
import java.util.*;
/**
 *
 * @author sabri
 */

public class Google_jamp_c {

    /**
     * @param args the command line arguments
     */
public static int recycled (int A, int B){
                int m = 0, c=0;
                String tmp = "", subB = "", subE = "", recycled = "";
                for (int n = A; n<B;n++)
                {
                        tmp = String.valueOf(n);
                        for (int j=0;j<tmp.length();j++)
                        {
                            subB = tmp.substring(0,j);
                            subE = tmp.substring(j);
                            recycled = subE+subB;
                            m = Integer.parseInt(recycled);
                            if ((m>n) && (m<=B)) 
                             {c++;}
                        }
                }
                return c;
        }
    public static void main(String[] args) throws FileNotFoundException, IOException {
        String ligne = "";
        int nbrLigne = 0,res,a,b;
        StringTokenizer st1;
        FileInputStream fStream = new FileInputStream("A-small-attempt.in");
		BufferedReader in = new BufferedReader(new InputStreamReader(fStream));
                if (in.ready()) {
			ligne = in.readLine();
			nbrLigne = Integer.parseInt(ligne);
      			for (int j = 0; j < nbrLigne; j++) {
				ligne = in.readLine();
                                st1=new StringTokenizer(ligne," ");
                                 a=Integer.parseInt(st1.nextToken());
                                  b=Integer.parseInt(st1.nextToken());
				System.out.print("Case #"+(j+1)+": ");
                                res=recycled(a,b);
                                System.out.print(res);
                          System.out.println("");
			}
		}
    }
}
