package fixjava;

public class StringUtils {

	/** Repeat the given string the requested number of times. */
	public static String repeat(String str, int numTimes) {
		StringBuilder buf = new StringBuilder(Math.max(0, str.length() * numTimes));
		for (int i = 0; i < numTimes; i++)
			buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the left hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padLeft(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(padChar);
		for (int i = 1, mi = bufSize - str.length(); i < mi; i++)
			buf.append(padChar);
		buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the right hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padRight(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(str);
		buf.append(padChar);
		while (buf.length() < bufSize)
			buf.append(padChar);
		return buf.toString();
	}

	/** Intern all strings in an array, skipping null elements. */
	public static String[] intern(String[] arr) {
		for (int i = 0; i < arr.length; i++)
			arr[i] = arr[i].intern();
		return arr;
	}

	/** Intern a string, ignoring null */
	public static String intern(String str) {
		return str == null ? null : str.intern();
	}

}

package codeJam2012_Qualification;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Scanner;
import java.util.TreeMap;

public class RecycledNumbers {
	private String FILE_NAME = "2012_QC_numbers_C-large";
	private TreeMap<Double,Long> numbers;
	private int maxNum = 2000000;
	
	private TreeMap<Double,Long> getNumbers() {
		if (numbers == null) {
			String value;
			long newNum;
			
			numbers = new TreeMap<Double,Long>();
			for (int i=10;i<=maxNum;i++) {
				value = String.valueOf(i);
				for (int pos=0;pos<value.length()-1;pos++) {
					long division = Math.round(Math.pow(10,pos+1)); 
					int power = value.length()-pos-1; 
					newNum = Math.round(i/division + (i%division)*Math.pow(10,power));
					
					if (i<newNum && newNum<=maxNum && value.length()==String.valueOf(newNum).length()) {
						numbers.put(Double.valueOf(i+"."+newNum),newNum);
					}
				}
			}
		}
		return numbers;
	}

	private int solve(String input) {
		Scanner sc = new Scanner(input);
		
		double lowest = sc.nextInt();
		double highest = sc.nextInt();
		int count = 0;
		
		NavigableMap<Double,Long> recycles = getNumbers().subMap(lowest, true, highest, true);
		for (Map.Entry<Double, Long> recycle : recycles.entrySet()) {
			if (recycle.getValue()<highest+1) {
				count++;
			}
		}
		
		return count;
	}
	
	public void run() throws IOException {
		Scanner sc = new Scanner(new FileReader(FILE_NAME+".in"));
		PrintWriter pw = new PrintWriter(new FileWriter(FILE_NAME+".out"));
		
		int cases = Integer.valueOf(sc.nextLine());
		for (int i=1;i<=cases;i++) {
			String input = sc.nextLine();
			System.out.println("Input #"+i+": "+input);

			String output = "Case #"+i+": "+solve(input);
			pw.println(output);
			System.out.println(output);
		}
		
		pw.flush();
		pw.close();
		sc.close();
	}
	public static void main(String[] args) throws IOException {
		new RecycledNumbers().run();
	}
}
