import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Recycled {
	public static void main(String[] args) throws Exception{
		String inputFile = "C-small-attempt0.in";
		
		BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
		BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output")));
		long num_cases = Long.parseLong(input.readLine());
		int current_case = 0;
		
		while (current_case < num_cases){
			current_case++;
			
			String[] fields = input.readLine().split(" ");
			int A = Integer.parseInt(fields[0]);
			int B = Integer.parseInt(fields[1]);
			int total = 0;
			
			for (int n = A; n < B; n++){
				for (int m = n+1; m <= B; m++){
					if (isRecycled(n,m)) total++;
				}
			}
			
			System.out.println("Case #" + current_case + ": " + total);
			output.write("Case #" + current_case + ": " + total + "\n");
		}
		output.close();
	}

	private static boolean isRecycled(int n, int m) {
		String sn = ""+n;
		String sm = ""+m;
		if (sn.length() != sm.length()) return false;
		int totaln = 0, totalm = 0;
		for (int i = 0; i < sn.length(); i++){
			totaln += sn.charAt(i);
			totalm += sm.charAt(i);
		}
		if (totaln != totalm) return false;
		for (int i = 0; i < sn.length()-1; i++){
			sm = sm.charAt(sm.length() - 1) + sm.substring(0, sm.length() - 1);
			if (sm.equals(sn)) return true;
		}
		return false;
	}
}

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class RecycledNumbers {
	public static void main(String args[]) throws FileNotFoundException {
		new RecycledNumbers().Go();
	}

	public void Go() throws FileNotFoundException {
		Scanner in = new Scanner(new File("test.txt"));
		int tests = Integer.parseInt(in.nextLine());
		for (int i = 0; i < tests; i++) {
			String[] line = in.nextLine().split("\\s+");
			int n = Integer.parseInt(line[0]);
			int m = Integer.parseInt(line[1]);
			System.out.println("Case #" + (i + 1) + ": "
					+ countPairs(n, m, 1, 1000));
		}
	}

	public int countPairs(int n, int m, int A, int B) {
		HashMap<Integer, LinkedList<Integer>> map = new HashMap<Integer, LinkedList<Integer>>();

		int count = 0;
		for (int i = n; i <= m; i++) {

			LinkedList<Integer> intList = permutations(i + "");
			map.put(i, intList);
			for (Integer it : intList) {
				if (map.containsKey(it)) {
					LinkedList<Integer> ints = map.get(it);
					if (ints.contains(i)) {
						count++;
					}
				}
			}
		}
		
		return count;
	}

	public LinkedList<Integer> permutations(String str) {
		LinkedList<Integer> numList = new LinkedList<Integer>();
		for (int i = 0; i < str.length(); i++) {
			Integer temp = Integer.parseInt(str);
			if (!numList.contains(temp))
				numList.add(Integer.parseInt(str));
			str = leftRotate(str);
		}
		numList.removeFirst();
		return numList;
	}

	public String leftRotate(String str) {
		StringBuilder build = new StringBuilder();
		build.append(str.substring(1, str.length()));
		build.append(str.charAt(0));
		return build.toString();
	}
}
