import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
import java.util.ArrayList;
import java.util.Arrays;
public class Problem3
{
    public void solve(){
        ReadWriter rw = new ReadWriter();
        ArrayList<String> input = rw.readFile("C-large.in");
        ArrayList<String> ans = new ArrayList<String>();
        int num;
        boolean first = true;
        int count=0;
        for(String s : input){
            if(first){
                num=Integer.parseInt(s);
                first=false;
            }
            else{
                String[] nums = s.split(" ");
                ans.add("Case #"+count+": "+countResults(nums));
            }
            count++;
        }
        rw.writeFile(ans, "output3.txt");
    }
    public int countResults(String[] nums){
        
        int min = Integer.parseInt(nums[0]);
        int max = Integer.parseInt(nums[1]);
        int temp = min;
        int count=0;
        while(temp<max){
            ArrayList<String> checked = new ArrayList<String>();
            String s = ""+temp;
            for(int i = 0;i<s.length();i++){
                if(s.substring(i,i+1).equals("0")){
                    continue;
                }
                String x = s.substring(i,s.length())+s.substring(0,i);
                
                int comp = Integer.parseInt(x);
                if(comp>temp&&comp<=max&&checked.indexOf(""+temp+" "+x)==-1){
                    count++;
                    checked.add(""+temp+" "+x);
                }
            }
            temp++;
        }
        return count;
    }
}
