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.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;


public class RecycledNumbers {
	
	
	static int findLessThanHundred(int a, int b){
		if (a==b) return 0;
		if (b < 22) return 0;
		int retour=0;
		if (b < 100) {
			int x=11;
			if (a > 11) x=a; else x = 12;
			while(x < b){
				
		String entier = x+"";
		if (!(entier.charAt(1)+"").equals("0")){
			
		int rec = Integer.parseInt(""+entier.charAt(1)+entier.charAt(0)+"");
				
		if (rec > x && rec < b+1 ) {System.out.println(rec);retour++;}
				
		}
			x++;	
			}
			
			
		return retour;	
			
		}
		
		
		
		
		
		return 0;
	} 
	
	
	static int findLessThanThousand(int a, int b){
		
		int retour = 0;
		ArrayList<String> arr = new ArrayList<String>();
		if (a==b) return 0;
		int x = a;
		while (x < b+1){
		if (!arr.contains(x+"")){
			boolean rec1good = false;
			int rec1=0,rec2=0;
		String entier= x+"";
		if (!(""+entier.charAt(2)+"").equals("0") ){
		rec1 = Integer.parseInt(""+entier.charAt(2)+""+entier.charAt(0)+""+entier.charAt(1)+""); 
		
		if (rec1 > a && rec1 < b+1 && rec1 != x ) {;arr.add(rec1+"");arr.add(x+"");retour++;rec1good=true;}
	
		}
		if (!(""+entier.charAt(1)+"").equals("0") ){
			rec2 = Integer.parseInt(""+entier.charAt(1)+""+entier.charAt(2)+""+entier.charAt(0)+""); 
			
			if (rec2 > a && rec2 < b+1 && rec2 != rec1 && rec2 != x) {arr.add(rec2+"");retour++; if (rec1good) retour++;}
		
			}
		System.out.println("x=="+x+"rec1=="+rec1+"rec2=="+rec2+" retour=="+retour);
		}
		x++;
		}
		
		
		return retour;
	}
	
	
	
	public static void main (String args[]) throws IOException{
	
		BufferedReader in = new BufferedReader(new FileReader(new File("recycled.in")));
		PrintWriter out = new PrintWriter(new FileWriter("recycled.out"));
		
		//System.out.print(RecycledNumbers.findLessThanHundred(10,40));
		
		//System.out.println(RecycledNumbers.findLessThanThousand(100,500));
		
		String ligne="";
		
		int nbr_lignes = Integer.parseInt(in.readLine());
		
		int index = 0;
		
		while(index < nbr_lignes){
		int a,b;
		ligne=in.readLine();
		StringTokenizer tok = new StringTokenizer(ligne);
		
		a = Integer.parseInt(tok.nextToken());
		b = Integer.parseInt(tok.nextToken());	
		
		if (b<100) {
			
			if (index!=nbr_lignes-1){
				out.println("Case #"+(index+1)+": "+RecycledNumbers.findLessThanHundred(a, b));
				}
			else 
				out.print("Case #"+(index+1)+": "+RecycledNumbers.findLessThanHundred(a, b));
			
			
		}
		
		
		else if (a > 99) {
			
			if (index!=nbr_lignes-1){
				out.println("Case #"+(index+1)+": "+(RecycledNumbers.findLessThanThousand(a, b)));
				}
			else 
				out.print("Case #"+(index+1)+": "+(RecycledNumbers.findLessThanThousand(a, b)));
			
							
			}
		
		else {
			
			if (index!=nbr_lignes-1){
				out.println("Case #"+(index+1)+": "+(RecycledNumbers.findLessThanHundred(a, 99)+RecycledNumbers.findLessThanThousand(100, b)));
				}
			else 
				out.print("Case #"+(index+1)+": "+(RecycledNumbers.findLessThanHundred(a, 99)+RecycledNumbers.findLessThanThousand(100, b)));
			
			
			
			
		}
			
			index++;
		}
			
			out.close();
			
			
		}
		
		
	

}
