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.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;


public class QualifiRound2012C {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			BufferedReader br = new BufferedReader(new FileReader(args[0]));
			PrintWriter pw = new PrintWriter(args[1]);
			String line = br.readLine();
			System.out.println(line);
			int T = Integer.valueOf(line.trim());
			for (int i=0; i<T; i++)
			{
				line = br.readLine();
				System.out.println(line);
				String[] input = line.trim().split(" ");
				int A = Integer.valueOf(input[0]);
				int B = Integer.valueOf(input[1]);
				long result = 0;
				
				for(int j=A; j<=B; j++)
				{
					int bit = (int)Math.floor(Math.log10(j));
					HashMap<Integer, Boolean> map = new HashMap<Integer, Boolean>();
					map.put(j, true);
					
					int pair = (j%10)*(int)Math.pow(10, bit)+ j/10;
					while(!map.containsKey(pair))
					{
						if(j>pair)
						{
							map.put(pair, true);
							pair = (pair%10)*(int)Math.pow(10, bit)+ pair/10;
							continue;
						}

						if(A<=pair && pair<=B)
							result++;
						pair = (pair%10)*(int)Math.pow(10, bit)+ pair/10;
						continue;
					}
				}
				
				pw.println("Case #"+(i+1)+": "+result);
				System.out.println("Case #"+(i+1)+": "+result);
			}
			pw.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
