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 codejam03;
import java.io.*;
import java.util.StringTokenizer;
public class CodeJam03
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T,A,B;
        String temp1,temp2;
        int output,n;
        T = Integer.parseInt(br.readLine());
        for(int i=0; i<T; i++)
        {
            output = 0;
            StringTokenizer st = new StringTokenizer(br.readLine());
            A = Integer.parseInt(st.nextToken());
            B = Integer.parseInt(st.nextToken());
            for(int j=A; j<B; j++)
            {
                temp1 = Integer.toString(j);
                for(int k=0; k<temp1.length(); k++)
                {
                    temp2 = temp1.substring(k+1) + temp1.substring(0, k+1);
                    n = Integer.parseInt(temp2);
                    if(n>j && Integer.parseInt(temp2)<=B) output++;
                    if(n==j) break;
                }
            }
            System.out.println("Case #" +(i+1) + ": " + output);
        }
    }
}
