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.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
class gcj3
{
    public static void main(String args[])throws Exception
    {
        Scanner in=new Scanner(new File("C:/Users/Rakesh/Downloads/C-small-attempt0.in"));
       // Scanner in=new Scanner(System.in);
        FileWriter fstream = new FileWriter("c:/out.out");
        BufferedWriter out = new BufferedWriter(fstream);
        int t,i,j,k,temp,m=0,c=0,l=0,ok=1,p,r;
        t=in.nextInt();
        int res[][]=new int[1000][2],a[]=new int[t],b[]=new int[t];
        for(i=0;i<t;i++)
        {
            a[i]=in.nextInt();
            b[i]=in.nextInt();
        }
        for(i=0;i<t;i++)
        {
            for(j=a[i];j<=b[i];j++)
            {
                for(k=j+1;k<=b[i];k++)
                {
                    temp=k;
                    while(temp>0)
                    {
                        temp/=10;
                        l++;
                    }
                    r=l;
                    temp=k;
                    ok=1;
                    while(l-->1)
                    {
                            temp=(int) ((temp/(Math.pow(10,(r-1))))+((temp%(Math.pow(10,(r-1))))*10));
                            if(temp==j && temp>=a[i] && temp<=b[i])
                             {c++;
                                 for(p=0;p<m;p++)
                                  {
                                       if(res[p][0]==j)
                                       {
                                          ok=0;
                                          break;
                                       }
                                  }
                                  if(ok==1)
                                    {
                                      // c++;
                                        if(k>=j)
                                        {
                                             res[m][0]=j;
                                             res[m++][1]=k;
                                        }
                                        else
                                         {
                                             res[m][0]=k;
                                             res[m++][1]=j;
                                         }
                                       // break;
                                    }
                              }
                        }
                    }
                }
            try
            {
              out.write("Case #"+(i+1)+": "+c+"\n");
            }
            catch (Exception e)
            {//Catch exception if any
                 System.err.println("Error: " + e.getMessage());
            }
            //System.out.println(c);
            c=0;
            }
        out.close();
        }
    }

        