import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Scanner;

public class C {
	private Scanner in;
	
	private PrintWriter out;
	
	private final String file = "C";
	
	public C() throws IOException {
		try {
			System.setIn(new FileInputStream("io/q/" + file));
			System.setOut(new PrintStream(new FileOutputStream("io/q/" + file + ".out")));
		} catch (FileNotFoundException e) {
			System.err.println(e.getMessage());
		}
		
		in = new Scanner(new BufferedInputStream(System.in));
		
		out = new PrintWriter(System.out);
		
		// for case
		int T = in.nextInt(), t = 1;
		int A, B, l, sum, total, currentNumberChar, currentNumber;
		HashMap<Integer, Boolean> map;
		
		while (T-- > 0) {
			A = in.nextInt();
			B = in.nextInt();
			map = new HashMap<Integer, Boolean>(B - A + 1);
			total = 0;
			
			if (A > 9) {
				final int size = (A + "").length() - 1;
				final int exp = (int) Math.pow(10, size);
				
				for (int nextNumber = A; nextNumber <= B; nextNumber++) {
					// processed
					if (null != map.get(nextNumber)) continue;
					
					// process
					map.put(nextNumber, true);
					
					currentNumber = nextNumber;
					sum = 0;
					
					for (l = 0; l++ < size;) {
						currentNumberChar = currentNumber % 10;
						currentNumber = currentNumberChar*exp + (int)Math.floor(currentNumber/10);
												
						if ((currentNumber >= A) && (currentNumber <= B)) {
							if (null == map.get(currentNumber)) {
								map.put(currentNumber, true);
								sum++;
							}
						}
						
					}
					total += sum + sum*(sum-1)/2;
				}
			}			
			out.printf("Case #%d: %d%n", t++, total);
		}
		in.close();
		out.flush();
		out.close();
	}
	
	public static void main(String[] args) throws IOException {
		new C();
	}
}