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.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;


public class recycled {
	private static File f = new File("C:/Users/Cybermask/Desktop/myfile.txt");
	private static File outfile = new File("C:/Users/Cybermask/Desktop/out.txt");
	private static BufferedReader reader;

	private static String read() throws Exception{
		return reader.readLine();
	}
	private static int toint(String s){
		return Integer.parseInt(s);
	}
	private static ArrayList<Object> reverse(ArrayList<Object>list){
		ArrayList<Object> result = new ArrayList<Object>();
		for(int i=0;i<list.size();i++)
			result.add(list.get(list.size()-i-1));
		return result;
		
	}
public static void main(String args[])throws Exception{
	reader = new BufferedReader(new FileReader(f));
	PrintWriter pw = new PrintWriter(outfile);
	int n = toint(read());
	for(int i = 0 ; i<n;i++){
		String string = read();
		Scanner s = new Scanner(string);
		s.useDelimiter(" ");
		int f = s.nextInt();
		int l = s.nextInt();
		int count = 0 ;
		pw.print("Case #"+(i+1)+": ");
	
		for(int k=f;k<=l;k++){
			String number = k+"";
			int first = toint(number);
			HashSet<Integer> hs = new HashSet<Integer>();
			for(int o=1;o<number.length();o++){
				
				String 	number2=number.substring(number.length()-o,number.length())+""+number.substring(0,number.length()-o);
				
		
				
				int result = toint(number2);
				if(number.length()==number2.length() &&result>=f && result<=l && result > first){
					hs.add(result);
				}
				
			}
			count+=hs.size();
		}
		pw.println(count);
		
		
	}
	pw.flush();
}
}