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 codejam;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Codejam {
    static final Scanner keyboard = new Scanner(System.in);
    public static void main(String[] args) {
    int casos = Integer.parseInt(keyboard.nextLine());
        for(int x=1; x<=casos;x++)
        {
           String a, b;
           String A[]=new String[1000];
           String linea;
           linea = keyboard.nextLine();
            	StringTokenizer tokens= new StringTokenizer(linea," ");
		a = tokens.nextToken();
                b = tokens.nextToken();
           int counter=0;
           for (int i=Integer.parseInt(a); i<Integer.parseInt(b); i++)
                {
                    String c = "" +i;
                    char[] achar = c.toCharArray();
                    if (achar.length==2)
                    {
                        int one=Integer.parseInt("" +achar[1])*10+Integer.parseInt("" +achar[0]); 
                        if (one<=Integer.parseInt(b)&&one>i)
                        counter+=1;
                    }
                     if (achar.length==3)
                    {
                        int one= Integer.parseInt("" +achar[2])*100+Integer.parseInt("" +achar[0])*10+Integer.parseInt("" +achar[1]); 
                        if (one<=Integer.parseInt(b)&&one>i)
                        counter+=1;
                        int two= Integer.parseInt("" +achar[1])*100+Integer.parseInt("" +achar[2])*10+Integer.parseInt("" +achar[0]); 
                        if (two<=Integer.parseInt(b)&&two>i)
                        counter+=1;
                    }
                }
           System.out.println("Case #" +x +": " +counter);
        }     
    }
}
