package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;


public class recycle {
	static Scanner kb ;
	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
PrintWriter out = new PrintWriter("answerrecycle.txt");
		 kb = new Scanner(System.in);
		int testcase = kb.nextInt();
		for(int i=0;i<testcase;i++){
			out.println("Case #"+(i+1)+": "+solve());
		}
		out.close();
	}
	private static int solve() {
		// TODO Auto-generated method stub
		
		int minnumber = kb.nextInt();
		int maxnumber = kb.nextInt();
		int answer = 0;
		for(int i=minnumber;i<=maxnumber;i++){
			ArrayList<Integer> mem = new ArrayList<Integer>();
			String number = Integer.toString(i);
			int s = (int)number.charAt(0)-48;
			for(int k=1;k<number.length();k++){
			int n = (int)number.charAt(k)-48;
			
			if(n>=s){
				
				String news =  number.substring(k,number.length())+number.substring(0,k);
				int numbernew = Integer.parseInt(news);
				if(numbernew<=maxnumber&&(!(numbernew<=i))&&news.length()==number.length()&&!mem.contains(numbernew)){
					answer++;
					//System.out.println(number+"_n>s_"+news);
					mem.add(numbernew);
				}
				
			}
			
		}
		
	}
		return answer;
	}
}
