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

}

/**
 * Write a description of class solver here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class solver
{
    public int aise(int a[],int k,int j)
    {
        int i;
        int temp=0;
        for(i=0;i<j;i++)
        {
            temp=temp*10+a[(i+k)%j];
        }
        return temp;
    }

    public int[] reverse(int a[],int j)
    {
        int i,temp;
        for(i=0;i<j/2;i++)
        {
            temp=a[i];
            a[i]=a[j-i-1];
            a[j-i-1]=temp;
        }
        return a;
    }

  public boolean greater(int a[],int i,int n)
  {
      int j=0;
      for(j=0;j<n;j++)
      {
          if(a[(i+j)%n]<a[j])
          return false;
          else if(a[(i+j)%n]>a[j])
          return true;
        }
        return false;
    }
    public boolean lesser(int a[],int b[],int k,int j,int n1)
    {
        if(j<n1)
        return true;
        else
        {
            int i=0;
            for(i=0;i<n1;i++)
            {
                if(a[(k+i)%j]>b[i])
                return false;
                else if(a[(k+i)%j]<b[i])
                return true;
            }
            return true;
        }
    }


    public int solve(int a,int b)
  {
      int i,k,s;
      int n1=0,temp,temp1=b,j;
      int[] arr=new int[10];
      int count=0;
      int[] arr2=new int[10];
      int[] comp=new int[10];
      while(temp1>0)
          {
              arr2[n1++]=temp1%10;
              temp1=temp1/10;
           }
    
      arr2=reverse(arr2,n1);
      for(i=a;i<b;i++)
      { 
          temp=i;
          j=0;
          while(temp>0)
          {
              arr[j++]=temp%10;
              temp=temp/10;
           }
           arr=reverse(arr,j);
           s=0;
           for(k=j-1;k>0;k--)
           {
               if(arr[k]!=0)
               {
                   if(greater(arr,k,j) && lesser(arr,arr2,k,j,n1))
                   {
                   count++;
                   comp[s++]=aise(arr,k,j);
                }
                }
            }
            for(k=0;k<s;k++)
            {
                for(j=k+1;j<s;j++)
                    {
                           if(comp[k]==comp[j])
                           {
                               count--;
                            }
                        }
                    }
                
            }
          return count;
        }
      
      
    }
    

