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.lang.*;
import java.io.*;
import java.util.*;

public class rotate{

public static void main(String args[])throws Exception{

int i,j,k,m;
int n_test_case;
FileInputStream fin = new FileInputStream("C-small-attempt0.in");
DataInputStream in = new DataInputStream(fin);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String str,tempN,tempM;
String ABstr[]=new String[2];
            FileWriter fout = new FileWriter("output.txt");
            BufferedWriter out = new BufferedWriter(fout);

            str = br.readLine();
            n_test_case=Integer.parseInt(str);

            for(i=0;i<n_test_case;i++)
            {
                int count=0;
                str = br.readLine();    
                ABstr = str.split(" ");
                //System.out.println(ABstr[0]+" "+ABstr[1]);
                int A,B;
                A=Integer.parseInt(ABstr[0]);//n
                B=Integer.parseInt(ABstr[1]);//m
                    for(j=A;j<B;j++)
                    {
                        ArrayList<Object> arl=new ArrayList<Object>();
                        for(k=j+1;k<=B;k++)
                        {
                            tempN= new Integer(j).toString();//n
                            tempM= new Integer(k).toString();//m
                            if(ABstr[0].length()>1)
                            {

                                 for(m=0;m<ABstr[0].length();m++)
                                 {
                                 
                                 //rotate
                                 if(tempN.equals(tempM) && arl.indexOf(tempN)==-1)
                                 {
                                     //System.out.println(tempN+" "+tempM);
                                     arl.add(tempN);
                                     count++;
                                     
                                 }
                                 else
                                 tempN=tempN.substring(tempN.length()-1,tempN.length())+tempN.substring(0,tempN.length()-1);
                                 while(tempN.charAt(0)=='0')    
                                 tempN=tempN.substring(tempN.length()-1,tempN.length())+tempN.substring(0,tempN.length()-1);
                                 }
                                
                            }
                            
                        }
                                                
                    }//each value of n is compared
                //System.out.println(count);
            if(i==n_test_case-1)
            str="Case #"+(i+1)+": "+count;
            else
            str="Case #"+(i+1)+": "+count+"\n";
            out.write(str);

            }//outer n_test_cases loop
            out.close();
}
}