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.util.*;
import java.io.*;
class recycle
{
	static int tes=0;
	public static void main(String[] args) 
	{
		String fileName="../Problem/C-small-attempt0.in";
		String outputFile="output-small.in";
		String ans="";
		List data=recycle.readFile(fileName);
		int testCase=Integer.parseInt(data.get(0).toString());
		for(int tc=1;tc<=testCase;tc++)
		{
			String[] ab=cutString(data.get(tc).toString());
			int n=Integer.parseInt(ab[0]);
			int m=Integer.parseInt(ab[1]);
			ans+="Case #"+tc+": "+recycle.process(n,m)+"\n";
		}
		writeFile(ans,outputFile);
		//recycle.swap("12345",1);
	}
	public static int process(int n,int m)
	{
		int rec=0;
		for(n=n;n<m;n++)
		{
            String aa=String.valueOf(n);
			//String test=""+n;
			//System.out.println(test);
			
			rec+=recycle.swap(aa,m);
			//System.out.println("REC MAIN="+rec);
		}
		//System.out.println("rec = "+rec);
		return rec;
	}
	public static int swap(String n,int m)
	{
		int rec=0;
		//String old=n;
		int l=n.length()-1;
		for(int y=0;y<n.length();y++)
		{
			String ans=""; //swap number
			for(int x=0;x<n.length();x++)//swap
			{
				//System.out.print(""+l);
				if(l==n.length()) l=0;
				ans+=n.charAt(l);
				l++;
			}
			l--;
			 
			if(ans.charAt(0)!='0')
			{
				//System.out.println(ans);
				int k=Integer.parseInt(ans.toString()); //new swap to int
				int o=Integer.parseInt(n.toString()); 
				if(k>o && k<=m) 
				{
					rec++;
					recycle.tes++;
					//System.out.println("(K="+k+"> O="+o+" && K="+k+"<m="+m+")Recy #"+recycle.tes+": ("+o+","+k+")");
				}

			}
		}
		return rec;
	}
	public static String[] cutString(String st)
	{
		String s[]=st.split(" ");
		return s;
	}
	public static List readFile(String pathFile)
	{
		List data=new ArrayList();
		File file=new File(pathFile);
		try
		{
			BufferedReader br=new BufferedReader(new FileReader(file));
			String text;
			while((text = br.readLine()) != null) data.add(text);
			br.close();
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		return data;
	}
	public static void writeFile(String output,String fileName)
	{
		try	
		{
			FileWriter fw=new FileWriter(fileName);
			BufferedWriter bw=new BufferedWriter(fw);
			String new_output[]=output.split("\n");
			for(int i=0;i<new_output.length;i++)
			{
				bw.write(new_output[i]);
				bw.newLine();
			}
			bw.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
}
