package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}

package C;
import java.io.*;

import java.util.ArrayList;
public class Main {


    public static void main(String[] args) {
        new Main().go();
    }


    public void go() {
        BufferedReader in = null;
        BufferedWriter out = null;
        try{
            in = new BufferedReader(new FileReader("C-small-attempt0.in"));
            out = new BufferedWriter(new FileWriter("C-small-attempt0.out"));
            int T = Integer.parseInt(in.readLine());
            System.out.println("T="+T);

            for(int i=0;i<T;i++){

                String[] line = in.readLine().split(" ");
                int A = Integer.parseInt(line[0]);
                int B = Integer.parseInt(line[1]);

                int win = 0;

                for(int x=A;x<B;x++){
                    int n=x;
                    if(n<10){
                        continue;
                    }
                    String N = Integer.toString(n);
                    int len = N.length();
                    ArrayList<Integer> list = new ArrayList<Integer>();
                    for(int k=1;k<len;k++){
                        String M = "";
                        for(int y=0;y<len;y++){
                             M = M + N.charAt((k+y)%len);
                        }
                        int m = Integer.parseInt(M);
                        if(m<=B&&m>n) {
                            boolean iswin = true;
                            for(int y=0;y<list.size();y++){
                                if(m==list.get(y)){
                                    iswin = false;
                                    break;
                                }
                            }
                            if(iswin){
                                win++;
                                list.add(m);
                            }
                        }
                    }                    
                }

                out.write("Case #"+(i+1)+": "+win+"\n");
                System.out.print("Case #"+(i+1)+": "+win+"\n");
            }
            in.close();
            out.close();
        }catch(Exception e){
            e.printStackTrace();
            try{
                in.close();
                out.close();
            }catch(Exception e1){
                e1.printStackTrace();
            }
        }
        System.out.print("DONE\n");
    }
}

