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 recyclednumbers;

import java.util.ArrayList;

public class RecycledNumbersCase {

    private int min;
    private int max;

    public RecycledNumbersCase(String scoreLine) {

        String[] integers = scoreLine.split(" ");
        if(integers.length > 2 || integers.length < 2) {
            throw new IllegalArgumentException("Exactly two please");
        }

        min = new Integer(integers[0]);
        max = new Integer(integers[1]);
    }

    public int recycledPairCountFromMinToMax() {
        int pairCount = 0;

        for(int i = min; i <= max; i++) {
            pairCount += cycledDigitsInRangeAndGreaterThan(i);
        }
        return pairCount;
    }

    private int cycledDigitsInRangeAndGreaterThan(final int value) {
        int matches = 0;
        final String originalValue = String.valueOf(value);
        String cycledValue = cycleFromBackToFront(originalValue);
        while(!cycledValue.equals(originalValue)) {
            int cycledVal = Integer.valueOf(cycledValue);
            if(cycledVal > value && cycledVal <= max) {
                matches++;
            }
            cycledValue = cycleFromBackToFront(cycledValue);
        }

        return matches;
    }


    public int getMin() {
        return min;
    }

    public int getMax() {
        return max;
    }

    public static String cycleFromBackToFront(String numToCycle) {
        final int numLength = numToCycle.length();
        return numToCycle.substring(numLength - 1) + numToCycle.substring(0, numLength - 1);
    }
}
