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));
			
		}
		
		
		

	}
	
	
}
package mgg.problems;

import java.util.ArrayList;
import java.util.List;

import mgg.utils.CombinatoryUtils;
import mgg.utils.FileUtil;
import mgg.utils.StringUtils;
import mgg.utils.Triplet;

/**
 * @author manolo
 * @date 14/04/12
 */
public class ProblemB {

	public final static String EXAMPLE_IN = "B-example.in";
	public final static String EXAMPLE_OUT = "B-example.out";

	public final static String B_SMALL_IN = "B-small-practice.in";
	public final static String B_SMALL_OUT = "B-small-practice.out";

	public final static String B_LARGE_IN = "B-large-practice.in";
	public final static String B_LARGE_OUT = "B-large-practice.out";

	public final static String delim = " ";

	public static String solve(FileUtil util) {
		
		String line = util.getLine();
		List<Integer> listOfArgs = StringUtils.stringWithIntegersToList(line, delim);
		//System.out.println("\tArgs = " + listOfArgs);
		
		int googlers = listOfArgs.get(0);
		System.out.println("\tGooglers = " + googlers);
		
		int surprisingScores = listOfArgs.get(1);
		System.out.println("\tSurprising scores = " + surprisingScores);
		
		int leastScore = listOfArgs.get(2);
		System.out.println("\tMinimum = " + leastScore);
		
		List<Integer> listOfScores = listOfArgs.subList(3, listOfArgs.size());
		System.out.println("\tScores = " + listOfScores);
		
		List<Triplet> listOfTriplets;
		List<List<Triplet>> listOfListOfTriplets = new ArrayList<List<Triplet>>();
		for(int score : listOfScores){
			
			listOfListOfTriplets.add(CombinatoryUtils.possibleTriplets(score));
		}
		
		System.out.println("\tPossible triplets: " + listOfListOfTriplets);
		
		List<List<Triplet>> scenarios = calculateScenarios(listOfListOfTriplets, surprisingScores);
		
		System.out.println("\tPossible scenarios: " + scenarios);

		return null;
	}

	private static List<List<Triplet>> calculateScenarios(
			List<List<Triplet>> listOfListOfTriplets, int surprisingScores) {
		
		return null;
	}

}
