import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
package codejam2012.qr;

import codejam.common.CodeHelper;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Chen Ling
 */
public class ProblemC {

    private static String SMALL_IN_FILE_NAME = "/codejam2012/qr/C-small.in";
    private static String LARGE_IN_FILE_NAME = "/codejam2012/qr/C-large.in";
    private static String SMALL_OUT_FILE_NAME = "/codejam2012/qr/C-small.out";
    private static String LARGE_OUT_FILE_NAME = "/codejam2012/qr/C-large.out";

    public static int solve(int start, int end) {
        int total = 0;
        for (int number = start; number < end + 1; number++) {
            String pairN = String.valueOf(number);
            if (pairN.length() == 1) {
                continue;
            }
            for (int i = 1; i < pairN.length(); i++) {
                String pairM = pairN.substring(i, pairN.length()) + pairN.substring(0, i);
                int pairMI = Integer.parseInt(pairM);
                if (pairMI >= start && pairMI > number && pairMI <= end) {
                    total++;
//                    System.out.print("Pair(" + pairN + ", " + pairM + ")");
//                    System.out.print(", Ture");
//                    System.out.println("");
                }

            }
        }
//        System.out.println("Total: " + total);
        return total;
    }

    public static void main(String[] args) {
//        ProblemC.solve(1111, 2222);
//        List<String> smallLinesIn = CodeHelper.loadInputLines(SMALL_IN_FILE_NAME);
//        List<String> smallOuts = new ArrayList<String>();
//        for (int i = 1; i < smallLinesIn.size(); i++) {
//            String[] numbers = smallLinesIn.get(i).split(" ");
//            int start = Integer.parseInt(numbers[0]);
//            int end = Integer.parseInt(numbers[1]);
//            smallOuts.add("Case #" + i + ": " + ProblemC.solve(start, end));
//        }
//        CodeHelper.writeOutputs(SMALL_OUT_FILE_NAME, smallOuts);

        List<String> largeLinesIn = CodeHelper.loadInputLines(LARGE_IN_FILE_NAME);
        List<String> largeOuts = new ArrayList<String>();
        for (int i = 1; i < largeLinesIn.size(); i++) {
            String[] numbers = largeLinesIn.get(i).split(" ");
            int start = Integer.parseInt(numbers[0]);
            int end = Integer.parseInt(numbers[1]);
            largeOuts.add("Case #" + i + ": " + ProblemC.solve(start, end));
        }
        CodeHelper.writeOutputs(LARGE_OUT_FILE_NAME, largeOuts);
    }
}
