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

}
/*
 * recycle nums
 */
package google.code.jam;

import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 *
 * @author Jake
 */


public class GoogleCodeJam {
    private static int Min;
    private static int Max;
    private static PrintWriter  out= null;
    private static File input;
    private static Scanner in;
    private static boolean used[];
    public static void main(String[] args) {
        input = new File("C:/Users/Jake/Documents/C-small-attempt1.in");
        String tmp ;
        int intTmp;
        int count = 1;
		try {
			out= new PrintWriter("C:/Users/Jake/Documents/out.txt");
                        in = new Scanner(input);
                        //in = new Scanner(System.in);
                        
                        in.nextLine();
                        while(in.hasNext()){
                            Min = in.nextInt();
                            Max = in.nextInt();
                            //in.nextLine();
                            intTmp = Runner();
                            out.println("Case #"+ count + ": " +intTmp);
                            count++;
                        }
                        out.flush();
                        
                        //tmp = in.nextLine();
                        
                        
                        //System.out.println(Runner());
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    private static int Runner(){
        //checks for the number of pairs between min and max
         used = new boolean[Max-Min];
        reset(used);
        int Count = 0;
        
        for(int a = Min; a < Max; a ++){
           reset(used);
           Count = Count + checker(a);
        }
        return Count;
    }
    private static int checker(int Try){
        //finds how many pairs are within the range
        int pairs= 0;
        int test=Try;
        String strtry = new String(Try +"");
        for(int a = 0; a <= strtry.length()-1; a ++){
            if(Integer.parseInt(strtry)<=Max && Integer.parseInt(strtry)>Try && !used[Integer.parseInt(strtry)-Min-1]){
                pairs ++;
                used[Integer.parseInt(strtry)-Min-1] = true;
                System.out.println("pair : "+Try+" < "+ strtry+ " < " + Max);
            }
        
            strtry = rotate(strtry);
        }
            
        return pairs;
    }
    private static String rotate(String num){
        //takes the end of the string and makes it the beging
        String tmp, last;
        last = ""+num.charAt(num.length()-1);
        tmp = num.substring(0,num.length()-1);
        num = last+ tmp;
        return num;
    }
    private static boolean[] reset(boolean a[]){
        //reset the check if used array
        for(int b = 0; b <a.length; b ++){
            a[b] = false;
        }
        return a;
    }
}
