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 google;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.ArrayList;

public class Interview {

	public static void main(String[] args) throws IOException, FileNotFoundException {
		

		
		BufferedReader file = new BufferedReader(new FileReader(args[0]));
		
		String line = file.readLine();
		
		PrintStream z = new PrintStream("output.txt");
		
		
		while (line != null && !line.equals("0")) {
			line = file.readLine();
			
			if (line == null) {
				break;
			}
			String[] input = line.split(" ");
			System.out.println("Case: " + caseNum);
			int numUniquePairs = processInput(input);
		
			z.println("Case #" + caseNum + ": " + numUniquePairs);
			System.out.println("Case #" + caseNum + ": " + numUniquePairs);
			caseNum++;
			uniqueTable.clear();
			
		}
		System.out.println("finished");

	}
	private static int caseNum = 1;
	private static HashSet<String> uniqueTable = new HashSet<String>();
	
	private static int processInput(String[] input) throws FileNotFoundException {
		
		int A = Integer.parseInt(input[0]);
		int B = Integer.parseInt(input[1]);
		
		int numUniquePairs = 0;
		for (int i=A; i < B; ++i) {
			for (int j=i+1; j <= B; ++j) {
				if (uniqueTable.add(""+i +","+j)) {
					if (isRecyclePair(i, j)) {
						numUniquePairs++;
					}
				}
			}
		}
		return numUniquePairs;
	}


	private static boolean isRecyclePair(Integer x, Integer y) {
		
		if (x.equals(y)) {
			return false;
		}
		String xStr = x.toString();
		String yStr = y.toString();
		
		for (int i=0; i<xStr.length(); ++i) {
			if (xStr.equals(yStr)) {
				return true;
			}
			char c = xStr.charAt(0);
			if (i < xStr.length() - 1) {
				xStr = xStr.substring(1) + c;
			}
		}
		for (int i=0; i<yStr.length(); ++i) {
			if (xStr.equals(yStr)) {
				return true;
			}
			char c = yStr.charAt(0);
			if (i < yStr.length() - 1) {
				yStr = yStr.substring(1) + c;
			}
		}
		return false;
	}
	
}



