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.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 * Google Code Jam 2012
 * 	Qualifier Round
 * 	Problem C
 * 
 * @author Brian Crockford
 */
public class GCJ20120C {
	public static final String inputFilename = "C-small-attempt0.in";	

	
	
	static class LongPair {		
		final long[] data = new long[2];
		
		public LongPair(long x, long y) {
			set(x, y);
		}
		
		public long getX() { return data[0]; }
		public long getY() { return data[1]; }
		public void set(long x, long y) {
			data[0] = Math.min(x,y); data[1] = Math.max(x,y);
		}
		
		@Override public boolean equals(Object o) {
			LongPair p = (LongPair) o;
			if (null != p) {
				return (data[0] == p.getX() && data[1] == p.getY())
						|| (data[1] == p.getY() && data[0] == p.getX());
			}
			return false;
		}
		
		@Override public int hashCode() {
	        long hash = 1;
	        hash = hash * 31 + data[0];
	        hash = hash * 31 + data[1];
	        return (int) hash;
		}
	}
	
	static class DataSet {
		private static HashSet<LongPair> pairs;
		static {
			pairs = new HashSet<LongPair>(500000);
		}
		
		public long begin,
					end;
		
		@Override
		public String toString() {
			return new StringBuilder("<$DataSet: ").append(begin).append(", ").append(end).append(">").toString();
		}
		
		public long countRecycles() {
			int digits = countDigits(begin);
			for (long i=begin; i<=end; ++i) {
				for (int j=1; j<digits; ++j) {
					long result = shiftLong(i, j);
					if (i != result && result >= begin && result <= end)
						pairs.add(new LongPair(i, result));
				}
			}
			long result = pairs.size();
			pairs.clear();
			return result;
		}
		
		public static DataSet parse(String s) {
			DataSet result = new DataSet();
				result.begin = Long.parseLong(s.substring(0, s.indexOf(' ')));
				result.end = Long.parseLong(s.substring(1+s.indexOf(' ')));
			return result;
		}
	}
	
	
	
	public static Reader getFileReader(String filename) {
		BufferedReader result = null;
		try {
			result = new BufferedReader(new FileReader(filename));
		}
		catch (FileNotFoundException e) {
			System.err.println("Couldn't find the file \""+filename+"\"");
			e.printStackTrace();
		}
		return result;
	}
	
	
	
	public static String readLine(BufferedReader reader) {
		try {
			return reader.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	
	public static void closeReader(Reader r) {
		try { 
			r.close(); 
		} catch (IOException e) { e.printStackTrace(); }
	}
	
	
	
	public static Writer getFileWriter(String filename) {
		BufferedWriter result = null;
		try {
			result = new BufferedWriter(new FileWriter(filename));
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	
	
	public static void writeLine(BufferedWriter writer, String line) {
		try {
			writer.write(line);
			writer.newLine();
		} catch (IOException e) { e.printStackTrace(); }
	}
	
	
	
	public static void closeWriter(Writer w) {
		try { 
			w.close(); 
		} catch (IOException e) { e.printStackTrace(); }
	}
	
	
	
	public static String formatCase(int caseNumber, long result) {
		return new StringBuilder("Case #").append(caseNumber).append(": ").append(result).toString();
	}
	
	
	
	public static int countDigits(long n) {
		return (int) 1 + (int)Math.floor(Math.log10(n));
	}
	
	
	public static int getDigit(long n, int digit) {
		return(int)(n/(long)Math.pow(10, digit-1)) % 10;
	}
	
	
	public static long shiftLong(long n, int digits) {
		long mask = (long) Math.pow(10, digits);
		long upshift = (long) Math.pow(10, (countDigits(n)-digits));
		return (upshift*(n%mask)) + (n/mask);		
	}
	
	
	
	public static void main(String[] args) {		
		BufferedReader in = (BufferedReader) getFileReader(inputFilename);
		int lineCount = Integer.parseInt(readLine(in));
		List<DataSet> dataSets = new ArrayList<DataSet>();
		for (int i=0; i<lineCount; ++i) {
			dataSets.add(DataSet.parse(readLine(in)));
		}
		closeReader(in);
		
		BufferedWriter out = (BufferedWriter) getFileWriter(inputFilename.replace(".in", ".out"));
		for (int i=0; i<lineCount; ++i) {
			long result = dataSets.get(i).countRecycles();
			System.out.println(formatCase(i+1, result));
			writeLine(out, formatCase(i+1, result));
		}
		closeWriter(out);
	}

}