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.FileWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * 
 */

/**
 * @author Bageshwar
 * 
 */
public class Recycle {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		
		long[] p = new long[] { 10, 100, 1000, 10000, 100000, 1000000, 10000000 };
		// HashSet<Long> set=new HashSet<Long>();

		// HashSet<String> set1=new HashSet<String>();

		BufferedReader fr = new BufferedReader(new FileReader(new File(args[0])));
		String str = fr.readLine();
		//System.out.println(str);
		int lines = Integer.parseInt(str);
		FileWriter writer = new FileWriter(new File(args[1]));
		StringTokenizer stk;
		for (int l = 0; l < lines; l++) {

			writer.write("Case #"+(l+1)+": ");
			str = fr.readLine();
			stk = new StringTokenizer(str," ");			
			
			long a = Integer.parseInt(stk.nextElement().toString());
			long b = Integer.parseInt(stk.nextElement().toString());
			int total = 0;
			long t = 0;
			int k = 0;
			int c = ("" + b).length() - 1;
			for (long i = a; i <= b; i++) {

				for (int j = 0; j < c; j++) {
					// rotate by j
					// j=j-1;
					k = c - j - 1;
					t = (i % p[j]) * p[k] + (i / p[j]);
					 System.out.print(" "+i+":"+t);
					if (t <= b && t >= a && i != t) {
						 System.out.print("!");
						// set.add(i);
						total++;
						//System.out.println("##########" + i + ">>" + t);
						// set1.add(e)
					}
				}
				System.out.println("");
			}

			System.out.println(total);
			System.out.println(total / 2);
			writer.write(total/2+"\r\n");
		}
		writer.close();
		fr.close();
	}

}
