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.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

public class RecycledNumbers {

	
	int A;
	int B;
	int count = 0;
	List pairs = new ArrayList<String>();
	
	public static void main(String[] args) {
		
		int T;
		
		BufferedReader bf;
		try {
			bf = new BufferedReader(new FileReader("C-small-attempt1.in"));
			T = Integer.parseInt(bf.readLine().trim());
			
			for (int i = 0; i <= T -1 ; i++) {
				
				RecycledNumbers rn = new RecycledNumbers();
				String[] line = bf.readLine().split(" ");
				rn.A = Integer.parseInt(line[0]);
				rn.B = Integer.parseInt(line[1]);
				rn.count = 0;
				
				rn.resolve();
				
				rn.printOut(i + 1);
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	private void printOut(int i) {
		
		System.out.println("Case #" + i + ": " + count);
	}

	private void resolve() {
		int min = A;
		int minLength;
		if(min < 12){
			min = 12;
		}
		
		while (min <= B){
			String minS = String.valueOf(min); 
			String start = "";
			String end = "";
			minLength = minS.length();
			for (int i = 0; i < minLength -1; i++) {
				start = minS.substring(0,i +1 );
				end = minS.substring(i +1);
				if ( checkNewPair(minS, start,end)){
					count += 1;
				}
			}
			min += 1;
		}
	}

	private boolean checkNewPair(String minS, String start, String end) {
		if (end.charAt(0) == '0'){
			return false;
		}
		
		int newNumber = Integer.parseInt(end + start);
		
		if (newNumber > B ){
			return false;
		}
		
		int min = Integer.parseInt(minS);
		
		String newPair = "";
		if (min < newNumber){
			newPair = minS +"," + newNumber;
		}else if(min > newNumber){
			return false;
		}else if (min == newNumber){
			return false;
		}
			
		if ( pairs.contains(newPair)){
			return false;
		}
		pairs.add(newPair);
		return true;
	}

}


