package codejam;

import java.util.*;
import java.io.*;

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

import java.io.*;

public class recycled {
	private boolean compare(String s1, String s2){
		String s3 = s2+s2;
		boolean result = s3.contains(s1);
		return result;
	}
	private void go() throws Exception {
		File infile = new File("C-small-attempt1.in");
		BufferedReader br = new BufferedReader(new InputStreamReader(
				new FileInputStream(infile)));
		int num_of_cases = Integer.parseInt(br.readLine());
		for (int i = 1; i <= num_of_cases; i++) {
			String[] case_str = br.readLine().split(" ");
			int begin_num = Integer.parseInt(case_str[0]);
			int end_num = Integer.parseInt(case_str[1]);
			int satisifed = 0;
			for(int k=begin_num;k<end_num;k++){
				if(k/10==0)continue;
				String cur_num_str = new Integer(k).toString();
				for(int j=k+1;j<=end_num;j++){
					if(compare(cur_num_str,new Integer(j).toString()))
							satisifed++;
				}
			}
			System.out.println("Case #"+i+": "+satisifed);
		}
	}
	public static void main(String[] args){
		try {
			new recycled().go();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
