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){}
	}
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Scanner;

public class GCJ12QRC
{
	private static int a, b, d;
	private static long c;
	private static String output, newline = System.getProperty("line.separator");

	public static void fun()
	{
		String s;
		int i, j, k;
		c = d = 0;
		for(i=a; i>0; i/=10)
			d++;

		for(i=a; i<b; i++) {
			s = "" + i;
			for(j=1; j<d; j++) {
				k = Integer.parseInt(s.substring(j) + s.substring(0, j));
				if(k>i && k<=b) {
					c++;
				}
			}
		}
	}

	public static void main(String[] args) throws IOException
	{
		long t2, t1 = System.currentTimeMillis();
		output = "";
		Scanner sc = new Scanner(new File("C-large.in"));
		int ntc = sc.nextInt();

		for(int w=1; w<=ntc; w++)
		{
			a = sc.nextInt();
			b = sc.nextInt();
			fun();
			output += "Case #" + w + ": " + c + newline;
		}
		sc.close();

		OutputStream fo = new FileOutputStream("C-large.out");
		fo.write(output.getBytes());
		fo.close();
		t2 = System.currentTimeMillis();
		System.out.println( "Time in millis : " + (t2-t1) );
	}
}
