import java.io.*;

class code1
{
	public static void main(String args[]) throws Exception 
	{
		File ii = new File ("C-small-attempt1.in");
		FileInputStream fis = new FileInputStream(ii);
		BufferedReader  br = new BufferedReader(new InputStreamReader (fis));
		int cases = Integer.parseInt(br.readLine());
		FileOutputStream fout = new FileOutputStream ("output.txt");
		DataOutputStream dout = new DataOutputStream (fout);
		int total=0;
		for(int i=0;i<cases;i++){
		String temp = br.readLine();
		String parts [] = temp.split(" ");
		int lower = Integer.parseInt(parts[0]);
		int upper = Integer.parseInt(parts[1]);
		System.out.println(lower+" "+upper);
		
		for(int j=lower;j<=upper;j++)
		{
			int abc = j;int length=0;
			if(j<10)continue;
			while (abc!=0){abc/=10;length++;}
			abc=j;
			for(int m=0;m<length-1;m++){
				int shift = abc%10;
				abc=abc/10;
				System.out.println("hi "+j);
				abc=abc+shift*power(10,length-1);
				if(abc<=upper&&shift!=0&&abc>j)total++;
				System.out.println(total);
			}
		}
 		dout.writeBytes("Case #"+(i+1)+ ": "+total+"\n");
 		total=0;
		}//for close
		
	}

	private static int power(int i, int j) {
		int no=1;
		for(int a=0;a<j;a++){no=10*no;}
		return no;
	}
}
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;


public class RecycledNumbers {
	static Scanner sc;
	public static void main(String a[]) throws FileNotFoundException
	{
		int n,i;
		int res;
		sc= new Scanner(new FileInputStream("d:\\test\\a.in"));
		PrintStream out=new PrintStream(new FileOutputStream("d:\\test\\a.out"));
		
		n=sc.nextInt();
		sc.nextLine();
		for(i=1;i<=n;i++)
		{
			res=process();
			out.println("Case #"+i+": "+res);
			
		}
	}
	static int process()
	{
		int res=0;
		int low,high,i;
		low=sc.nextInt();
		high=sc.nextInt();
		for(i=low;i<=high;i++)
			res+=value(i,low,high);
		res=res/2;
		return res;
	}
	static int value(int a,int low,int high)
	{
		int i,res=0,n=1,p=10,q,val,prev=0;
		if(a<10) return 0;
		if(a<100)
		{
			n=2;
			q=10;
		}
		else if(a<1000)
		{
			n=3;
			q=100;
		}
		else if(a<10000) 
		{
			n=4;
			q=1000;
		}
		else if(a<100000) 
		{
			n=5;
			q=10000;
		}
		else if(a<1000000) 
		{
			n=6;
			q=100000;
		}
		else  
		{
			n=7;
			q=1000000;
		}
		for(i=1;i<n;i++)
		{
			val = ((a%p)*q)+(a/p);
			if(val>=low && val<=high && val!=a && val!=prev)
			{
				prev=val;
				res++;
			}
			p=p*10;
			q=q/10;
		}
		return res;
	}
}
