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.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;


public class RecycledNumbers {
	
	static ArrayList<Integer> perm(int j){
		ArrayList<Integer> ret = new ArrayList<Integer>();
		String num = j+"";
		int aux;
		for(int i=0; i<num.length(); i++){
			num=num.substring(1)+num.charAt(0);
			aux=Integer.parseInt(num);
			if((aux+"").length()==num.length())
				ret.add(aux);
		}
		return ret; 
	}
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(new FileReader("C-small-attempt0.in"));
		//Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(new FileWriter("solution.out"));
		
		int cas= in.nextInt();
		in.nextLine();
		for(int i=1; i<=cas; i++){
			int a, b, res=0;
			HashSet<Map<Integer, Integer>>conj= new HashSet<Map<Integer, Integer>>();
			HashMap<Integer, Integer>aux;
			a= in.nextInt();
			b= in.nextInt();
			for(int j=a; j<=b; j++){
				ArrayList<Integer> arr=perm(j);
	            for(int h=0; h<arr.size(); h++){
	            	aux= new HashMap<Integer, Integer>();
	            	aux.put(Math.min(j, arr.get(h)), Math.max(j, arr.get(h)));
	            	if(arr.get(h)!=j && arr.get(h)<=b && arr.get(h)>=a && !conj.contains(aux)){
	            		res++;
	            		conj.add(aux);
	            	}
	            }
	        }

			out.println("Case #"+i+": "+res);
		}
		out.close();
		System.exit(0);


	}

}
