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.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;


public class C {

	public final String INPUT_FILE_NAME = "c_in";
	public final String OUTPUT_FILE_NAME = "c_out";
	
	int kase = 1;
	int T = 0;
	int a,b;
	public void run() throws IOException{
		Scanner s = new Scanner(new File(INPUT_FILE_NAME));
		PrintWriter pw = new PrintWriter(new FileWriter(OUTPUT_FILE_NAME));
		//PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
		
		T = s.nextInt();
		while (T-- > 0){
			a = s.nextInt();
			b = s.nextInt();
			int len = ("" + a).length();
			
			int ans = 0;
			for (int i = a; i <=b ; i++) {
				String s1 = i + "";
				String temp = "";
				for (int k = 1; k < s1.length() ; k++) {
					temp = s1.substring(s1.length() - k) + s1.substring(0,s1.length()-k);
					int r1 = Integer.parseInt(temp); 
					if (r1 > i && r1 <= b)
						ans++;
				}
			}
			
			pw.println("Case #" + kase + ": " + ans);
			kase++;
		}
		
		pw.close();
		s.close();
	}
	
	
	public static void main(String[] args) throws IOException {
		(new C()).run();
	}

}
