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.util.*;
public class b {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		String ss = sc.nextLine();
		int casenum = Integer.parseInt(ss);
		String answer = "";
		for(int i = 1;i<=casenum;i++){
			answer = answer.concat("Case #".concat(Integer.toString(i)).concat(": "));
			ss = sc.nextLine();
			String wer = recycledpair(ss);
			answer = answer.concat(wer);
			answer = answer.concat("\n");
		}
		System.out.print(answer);
	}
	
	public static String recycledpair(String a){
		int n = Integer.parseInt(a.substring(0, a.indexOf(' ')));
		int m = Integer.parseInt(a.substring(a.indexOf(' ')+1, a.length()));
		int nlength = a.substring(0, a.indexOf(' ')).length();
		int pairnum = 0;
		String rcp ="";
		for(int i=n; i<m; i++){
			LinkedList<Integer> mylist = new LinkedList<Integer>();
			String sn = Integer.toString(i);
				//a.substring(0, a.indexOf(' '));
			for(int j=1; j<sn.length(); j++){
				String newnum = sn.substring(j,sn.length()).concat(sn.substring(0,j));
				int newint = Integer.parseInt(newnum);
				if(newint>i&&newint<=m){
					if(!mylist.contains(newint)){
					pairnum++;
					mylist.add(newint);
					}
					else{
						mylist.add(newint);
					}
				}
			}
		}
		String snumreturn = Integer.toString(pairnum);
		//System.out.print(snumreturn);
		return snumreturn;
	}
}
