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.*;
import java.util.*;

public class QualC {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int z = Integer.parseInt(br.readLine());
		int[] ten = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};
		
		for(int i=0; i<z; i++){
			String[] s = br.readLine().split("\\s+");
			
			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);
			
			int n = Integer.toString(a).length();
			
			HashSet<String> hs = new HashSet<String>();
			
			for(int j=a; j<b; j++){
				int t = j;
				
				for(int k=1; k<n; k++){
					int tt = t%ten[k];
					int ttt = t/ten[k];
					
					int tttt = tt*ten[n-k] + ttt;
					
					if(t < tttt && tttt <= b){
						String ss = Integer.toString(t);
						String sss = Integer.toString(tttt);
						
						hs.add(ss + sss);
					}
				}
			}
			
			System.out.println("Case #" + (i+1) + ": " + hs.size());
		}
	}
}
