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 tr0llhoehle.cakemix.utility.googleCodeJam;

import java.text.ParseException;

/**
 * This class is a base class for all concrete problems. It is used to define
 * some methods necessary for the IOManager to work. It is crucial that the
 * addValue-Method gets extended and called (super.addValue(o)) by the extending
 * class.
 * 
 * @author Cakemix
 * @see IOManager
 * @see Solver
 */
public abstract class Problem {

    protected SupportedTypes[] types;
    protected int cntr = 0;
    protected boolean isInitialised = false;

    /**
     * Returns an array of SupportedTypes which define exactly what data is
     * stored in this problem.
     * 
     * The attribute "types" needs to be initialized in the constructor of the
     * extending class.
     * 
     * @return An array of SupportedTypes which define exactly what data is
     *         stored in this problem.
     * @see SupportedTypes
     */
    public SupportedTypes[] getTypes() {
	return types;
    }

    public void addValue(Object o) throws ParseException {
	if (!isInitialised) {
	    cntr++;
	    isInitialised = (cntr == types.length);
	} else {
	    throw new ParseException("Tried to add another value to this Problem even though all values are set.", cntr);
	}
    }
}
