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

/** Adapted from http://www.johndcook.com/standard_deviation.html */
public class RunningStats {

	int n = 0;
	double oldM, newM, oldS, newS, min, max;

	public void clear() {
		n = 0;
	}

	public void add(double x) {
		n++;

		// See Knuth TAOCP vol 2, 3rd edition, page 232
		if (n == 1) {
			oldM = newM = min = max = x;
			oldS = 0.0;
		} else {
			newM = oldM + (x - oldM) / n;
			newS = oldS + (x - oldM) * (x - newM);
			min = Math.min(min, x);
			max = Math.max(max, x);
			
			// set up for next iteration
			oldM = newM;
			oldS = newS;
		}
	}

	public int numValues() {
		return n;
	}

	public double mean() {
		return (n > 0) ? newM : 0.0;
	}

	public double variance() {
		return ((n > 1) ? newS / (n - 1) : 0.0);
	}

	public double stdDev() {
		return Math.sqrt(variance());
	}
	
	public double min() {
		return (n > 0) ? min : 0.0;
	}
	
	public double max() {
		return (n > 0) ? max : 0.0;
	}
}
