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;
	}
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package codejam;

/**
 *
 * @author PRATIK
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int test=args.length/2;
      

        int len=0,i,m,tem,val=0,l=0,count=0,count1=0,j=1,k;
        char arr[];
        String sec;
        int secnd;
        char temp;
        int f=1;
        int[] array=new int[500];
        int[][] array1=new int[1000][2];
        while(test!=0)
        {
            int start=Integer.parseInt(args[f]);
            int end=Integer.parseInt(args[f+1]);
            while(start<end)
            {
            String st=String.valueOf(start);
            len=st.length();
            char arr1[]=new char[len];
            if(len>1)
            {
            for(i=0;i<len;i++)
            {
                arr=st.toCharArray();

                temp=arr[len-1];
                for(k=1;k<len;k++)
                    arr1[k]=arr[k-1];
                arr1[0]=temp;
                st=String.valueOf(arr1);
                val=Integer.parseInt(st);
                if(val<=end && val>start)
                {
                    array1[l][0]=start;
                    array1[l][1]=Integer.parseInt(st);
                    l++;
                    count1++;
                }

            }
            }
            start++;
            }
            for(i=0;i<l;i++)
            {
                for(k=i+1;k<l;k++)
                {
                    if(array1[k][0]==array1[i][0] && array1[k][1]==array1[i][1])
                    {
                        if(count1>0)
                     count1--;
                    }
                }
            }


            System.out.println("Case #"+j+ ": "+count1);
            j++;
            test--;
            count1=0;
            f=f+2;
            l=0;
        }
    }

}
