import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;


public class Recycled {
	static int n = 1;
	
	static void solve(int A, int B) {
		int len = ("" + A).length();
		int min = 1;
		for (int a = 1; a < len; a++)
			min *= 10;
		
		int res = 0;
		
		int[] seen = new int[len];
		int nseen;
		
		for (int n = A; n < B; n++) {
			int m = n;
			nseen = 0;
			for (int a = 1; a < len; a++) {
				m = (m / 10) + (m % 10) * min;
				if (m >= min && n < m && m <= B) {
					boolean already = false;
					for (int b = 0; b < nseen; b++)
						if (seen[b] == m)
							already = true;
					if (!already) {
						res++;
						seen[nseen++] = m;
					}
				}
			}
		}
		
		System.out.println("Case #" + (n++) + ": " + res);
	}
	
	public static void main(String[] args) throws IOException {
		LineNumberReader in = new LineNumberReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine().trim());
		
		for (int a = 0; a < n; a++) {
			String[] l = in.readLine().trim().split(" ");
			solve(Integer.parseInt(l[0]), Integer.parseInt(l[1]));
		}
	}
}
