import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Q3M {
	public static void main(String[] args) throws Exception {
		compute();
	}

	private static void compute() throws Exception {
		BufferedReader br = new BufferedReader(new FileReader(new File(
				"C:\\work\\Q3\\C-small-attempt0.in")));
		String line = null;
		int i = Integer.parseInt(br.readLine());
		List l = new ArrayList();
		for (int j = 0; j < i; j++) {
			line = br.readLine();
			String[] nums = line.split(" ");
			l.add(calculate(nums));
		}
		writeOutput(l);
	}

	private static int calculate(String[] nums) {
		int min = Integer.parseInt(nums[0]);
		int max = Integer.parseInt(nums[1]);
		int count = 0;
		List l = new ArrayList();
		for (int i = min; i <= max; i++) {
			for (int times = 1; times < countDigits(i); times++) {
				int res = shiftNum(i, times);
				if (res <= max && i < res) {
					if ((!l.contains((i + ":" + res)))) {
						l.add(i + ":" + res);
						l.add(res + ":" + i);
						count++;
					}
				}
			}
		}
		return count;
	}

	private static boolean checkZeros(int temp, int res) {
		if (temp % 10 == 0 || res % 10 == 0)
			return false;
		return true;
	}

	private static int shiftNum(int n, int times) {
		int base = (int) Math.pow(10, times);
		int temp2 = n / base;
		int placeHolder = (int) Math.pow((double) 10,
				(double) countDigits(temp2));
		int res = placeHolder * (n % base) + temp2;
		if (countDigits(res) == countDigits(n)) {
			return res;
		} else {
			return 2000001;
		}
	}

	public static int countDigits(int x) {
		if (x < 10)
			return 1;
		else {
			return 1 + countDigits(x / 10);
		}
	}

	private static void writeOutput(List l) throws Exception {
		StringBuffer b = new StringBuffer();
		int i = 1;
		BufferedWriter br = new BufferedWriter(new FileWriter(new File(
				"C:\\work\\Q3\\ans.txt")));
		for (Iterator iterator = l.iterator(); iterator.hasNext();) {
			br.write("Case #" + i++ + ": " + iterator.next());
			br.newLine();
		}
		br.close();
	}

}
package googlecodejam;

import java.io.*;
/**
 *
 * @author $Ruslan
 */
public class Recycled_numbers {
	private static FileInputStream fileInputStream;
	private static int testCaseNumber = -1;
	public static void main(String[] args)
	{
		String filepath = "D:\\Programming\\NetBeansProjects\\" + ""
				+ "GoogleCodeJam\\src\\googlecodejam\\C-small-attempt0.in";
		try{
			if (args[0] != "")
			{
				filepath = args[0];
			}
		} catch (Exception e) {
			
		}
		
		try{
			fileInputStream = new FileInputStream(filepath);
			readInput();
		} catch (Exception e) {
			System.err.println("Exception: " + e.getMessage());
		}
	}
	
	
		private static void readInput()
	{
		try {
			String str;

			DataInputStream in = new DataInputStream(fileInputStream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));

			str = br.readLine();
			testCaseNumber = Integer.parseInt(str);
			System.out.println(testCaseNumber);

			for (int i = 0; i < testCaseNumber; i++)
			{
				System.out.print("Case #"+(i+1)+":");
				str = br.readLine();
				//calculate(str); //do smt!!!!
				recycleNumbers(str);
			}
			in.close();
		} catch (IOException | NumberFormatException e) {
			System.err.println("Exception: " + e.getMessage());
		}
	}
		
	private static void recycleNumbers(String str)
	{
		//with A â¤ n < m â¤ B
		String[] splitedStr = str.split(" ");
		int start_num = Integer.parseInt(splitedStr[0]);
		int end_num = Integer.parseInt(splitedStr[1]);
		int answer = 0;
		int reversedNum = -1;
		int positions = -1;
		int rest_right = -1;
		int rest_left = -1;
		if (start_num < 10)
		{
			start_num = 12;
		}
		for (int i = start_num; i < end_num; i++)
		{
			//PIZDEC	
			positions = 0;
			reversedNum = i;
			while (reversedNum > 0)
			{
				reversedNum /= 10;
				positions++;
			}
			for (int k = 1; k < positions; k++)
			{
				//Ex: 7487
				//k = 2;
				//rest_right = 87;
				//rest_left = 74;
				//if rest_right > rest_left then we can move it
				//otherwise it's gonna be less the the current num
				//and so on with each k
				rest_right = i % pow(10,k); //right part of the num
				rest_left = i / pow(10, (positions-k)); //left part of the num
				if (rest_right >= rest_left)
				{
					reversedNum = reverseNumber(i, k, positions);
					if ((reversedNum > i) && (reversedNum <= end_num))
					{
						answer++;
					}
				}
			}
		}
		System.out.println(" " + answer);
	}
	
	private static int reverseNumber(int number, int places, int positions)
	{
		int res = number % pow(10, places);
		number /= pow(10, places);
		res *= pow(10, (positions-places));
		res += number;
		return res;
	}
	
	private static int pow(int num, int pow)
	{
		int result = num;
		for (int i = 1; i < pow; i++)
		{
			result *= num;
		}
		return result;
	}
}
