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;


public class inpOutHandler {

	public testCase readInput(String fname, int linesInTestCase){
		testCase allCases;
		ArrayList<String> lineList = new ArrayList<String>();
		BufferedReader rd = null;
			try {
				rd = new BufferedReader(new FileReader(fname));
				while (true) {
					String line = rd.readLine();
					if (line == null) break;
					lineList.add(line);
				}
				rd.close();
			} catch (IOException ex) {
				System.out.println("Can't open that file.");
			} 
			//for(int i=0;i<lineList.size();i++)
				//System.out.println("<" + lineList.get(i) + ">");
			
		int N = Integer.parseInt(lineList.get(0));
			//int N=100;
		allCases = new testCase(N);
		int index=1;
		for(int i=0;i<N;i++){
			String tempS="";
			for(int j=0;j<linesInTestCase;j++){
				if(j==linesInTestCase-1){
				tempS += lineList.get(index++);
				}else{
					tempS += lineList.get(index++) +"\n";
				}
			}
			allCases.addCase(tempS);
		}
		return allCases;
	}
	
	public void createOutput(String fname, String content){
		try{
			  // Create file 
			  FileWriter fstream = new FileWriter(fname);
			  BufferedWriter out = new BufferedWriter(fstream);
			  out.write(content);
			  //Close the output stream
			  out.close();
			  }catch (Exception e){//Catch exception if any
			  System.err.println("Error: " + e.getMessage());
			  }
	}
}
