import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

import java.io.*;

public class Recycle {
	public static void main(String args[]) {
		try {
			InputStreamReader inReader = new InputStreamReader(new FileInputStream("input.txt"));
			BufferedReader br = new BufferedReader(inReader);
			
			File out = new File("output.txt");
			Writer output = new BufferedWriter(new FileWriter(out));
			
			int amount = Integer.parseInt(br.readLine());
			
			for (int i=0; i < amount; i++) {
				output.write("Case #" + (i+1) + ": ");
				String line = br.readLine();
				
				int min = Integer.parseInt(line.split(" ")[0]);
				int max = Integer.parseInt(line.split(" ")[1]);
				
				int result = 0;
				int digits = 1;
				int tmp = max;
				
				while (tmp/10 > 0) {
					tmp /= 10;
					digits++;
				}
				
				int[] assist = new int[digits];
				for (int l=0; l < digits; l++)
					assist[l] = 0;
				
				for (int j=min; j <= max; j++) {
					int number = j;
					int counter = 0;
					for (int k=1; k < digits; k++) {
						int newNumber = (int) ((int) (number%Math.pow(10, k)) * Math.pow(10, digits-k) + (number/Math.pow(10, k)));
						if (newNumber > number && newNumber <= max) {
							for (int l=0; l < counter; l++) {
								if (assist[l] == newNumber)
									result--;
							}
							
							assist[counter++] = newNumber;
							result++;
						}
					}
				}
				
				output.write(result + "\n");
			}
			
			output.close();
		}
		
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}