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 com.googlecodejam.gcj2012.qualificationround;

import java.io.File;
import java.io.FileWriter;
import java.util.HashSet;
import java.util.Scanner;

public class C {

//	public final static String INPUT_FILE_NAME = "test.in";
	public final static String INPUT_FILE_NAME = "C-small-attempt0.in";
//	public final static String INPUT_FILE_NAME = "C-large.in";
	
	public FileWriter outputWriter;
	public Scanner scanner;
	public String output = "";
	
	public void run() throws Exception {
		// Commons variables
		int testCaseNumber = 0;
		int testCaseResult = 0;
		// Test start
		{
			int nbTests = Integer.parseInt(scanner.nextLine());
			
			for (testCaseNumber = 0; testCaseNumber < nbTests; testCaseNumber++) {
				String[] bounds = scanner.nextLine().split(" ");
				String sMinValue = bounds[0];
				String sMaxValue = bounds[1];
				int minValue = Integer.parseInt(sMinValue);
				int maxValue = Integer.parseInt(sMaxValue);
				int nbDigits = sMinValue.length();
				testCaseResult = 0;
				if (nbDigits > 1) {
					for (int currentValue = minValue; currentValue < maxValue; currentValue++) {
						HashSet<Integer> foundValues = new HashSet<Integer>();
						String sCurrentValue = Integer.toString(currentValue);
						char firstNumber = sCurrentValue.charAt(0);
						for (int i = nbDigits - 1; i > 0; i--) {
							char number = sCurrentValue.charAt(i);
							if (number >= firstNumber) {
								String firstPart = sCurrentValue.substring(0, i);
								String secondPart = sCurrentValue.substring(i);
								int val = Integer.parseInt(secondPart + firstPart);
								if (val <= maxValue && val > currentValue && !foundValues.contains(val)) {
									testCaseResult++;
									foundValues.add(val);
								}
							}
						}
					}
				}
				
				output += "Case #" + (testCaseNumber+1) + ": " + testCaseResult + "\n";
			}
		}
	}
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////
	
	public void init() throws Exception {
		File temp = new File("output/");
		if (!temp.exists()) {
			temp.mkdir();
		}
		// Output file
		outputWriter = new FileWriter("output/output.txt", false);
		// Input file
		scanner = new Scanner(new File("resources/" + INPUT_FILE_NAME));
	}

	public void stop() throws Exception {
		// Closing files
		outputWriter.write(output, 0, output.length());
		scanner.close();
		outputWriter.close();
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		C instance = new C();
		long start = System.currentTimeMillis();
		
		instance.init();
		instance.run();
		instance.stop();
		
		System.out.println("Finished in " + (System.currentTimeMillis() - start) + " ms");
	}
	
}
