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.*;
import java.text.*;
import java.util.*;

public class RecycledNumbers {
	
	static BufferedReader stdin;
	static StringTokenizer st;

	static String LINE() throws Exception { return stdin.readLine(); }
	static String TOKEN() throws Exception {
		while (st == null || !st.hasMoreTokens())st = new StringTokenizer(LINE());
		return st.nextToken();
	}
	static int INT() throws Exception {return Integer.parseInt(TOKEN());}
	static long LONG() throws Exception {return Long.parseLong(TOKEN());}
	static double DOUBLE() throws Exception {return Double.parseDouble(TOKEN());}

	
	static DecimalFormat DF = new DecimalFormat("0.000",new DecimalFormatSymbols(Locale.ENGLISH));
	
	
	public static void main(String[] args) throws Exception {
		String input = "C-large.in";
		String output = "C-large.out";
//		String input = "testa.in";
//		String output = "testa.out";
		stdin = new BufferedReader(new FileReader(new File(input)));
		FileWriter frw = new FileWriter(output);
		
		int cases = INT();
		int cc = 1;
		while(cases-->0) {
			System.out.println(cc);
			int N = INT(), M = INT();
			int cp = N / 10;
			int factor = 1;
			while(cp>0) {
				factor *= 10;
				cp /= 10;
			}
			int solution = 0;
			for(int i = N; i < M; i++) {
				
				solution += addPairs(i, factor, M);
				
			}
			
			frw.write("Case #"+(cc++)+": ");
			frw.write(""+solution);
			frw.write("\n");
			
		}
		frw.flush();
		frw.close();
		
		
		
	}
	private static int addPairs(int i, int factor, int max) {
		int cnt = 0;
		int num = i;
//		System.out.println(i+" "+factor+" "+max);
		do {
//			System.out.println(num);
			int tmp = num;
			tmp /= 10;
			tmp += factor * (num % 10);
			num = tmp;
			if(num > i && num <= max)cnt++;
		} while (num != i);
		
		return cnt;
	}

}
