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

}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.regex.Pattern;

public class Solver {
	private static final String SMALL_FILE = "C-small-attempt0";

	// private static final String SMALL_FILE = "C-practice";

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		String inFileName = SMALL_FILE + ".in";
		String outFileName = SMALL_FILE + ".out";
		String path = new File(".").getAbsoluteFile().getParent();
		if (!path.endsWith(File.separator)) {
			path = path + File.separator;
		}
		path = path + "res";
		path = path + File.separator;
		int dataCount = 0;
		FileReader fileReader = null;
		BufferedReader buffer = null;
		try {
			fileReader = new FileReader(path + inFileName);
			buffer = new BufferedReader(fileReader);
			String count = buffer.readLine();
			if (count == null || !Pattern.matches("^[0-9]+$", count)) {
				buffer.close();
				fileReader.close();
				System.out.println("file invalid1");
				return;
			}
			dataCount = Integer.valueOf(count);
		} catch (IOException ex) {
			System.out.println("file read error1");
			return;
		}

		File file = new File(path + outFileName);
		PrintWriter writer = null;
		FileWriter fileWriter = null;
		BufferedWriter bw = null;
		try {
			fileWriter = new FileWriter(file);
			bw = new BufferedWriter(fileWriter);
			writer = new PrintWriter(bw);
		} catch (IOException ex) {
			System.out.println("file writer error");
			return;
		}

		for (int i = 1; i <= dataCount; i++) {
			try {
				String[] inputs = buffer.readLine().split(" ");

				int result = solve(Integer.valueOf(inputs[0]),
						Integer.valueOf(inputs[1]));

				writer.println(String.format("Case #%d: %d", i, result));
				System.out.println(String.format("%d", result));
			} catch (IOException ex) {
				System.out.println("file read error");
				return;
			}
		}

		try {
			buffer.close();
			writer.close();
			bw.close();
			fileWriter.close();
		} catch (IOException ex) {
		}
		long stop = System.currentTimeMillis();
		System.out.println(String.format("End %dms", stop - start));
	}

	private static int solve(int inputA, int inputB) {
		int count = 0;

		for (int i = inputA; i <= inputB; i++) {
			final String checkStr = String.valueOf(i);
			final int length = checkStr.length();
			ArrayList<String> contain = new ArrayList<String>();
			contain.add(checkStr);
			for (int j = 1; j < length; j++) {
				String reverse = checkStr.substring(length - j)
						+ checkStr.substring(0, length - j);
				if (contain.contains(reverse))
					continue;
				contain.add(reverse);
				int reverseInt = Integer.valueOf(reverse);
				if (reverseInt >= i && reverseInt <= inputB) {
					System.out.println(reverseInt);
					count++;
				}
			}
		}

		return count;
	}

}
