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.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Hashtable;


public class GJ_QR_C {

    public static int recycle(int A, int n){
        String st = (new Integer(A)).toString();
        return Integer.parseInt(st.substring(n) + st.substring(0, n));
    }
    public static int solve(int A, int B){
        
        String st = (new Integer(A)).toString();
        String ed = (new Integer(B)).toString();
        int res = 0;
        
        int N = st.length();
        for (int i = A; i<B+1; i++) {
            String tmp = (new Integer(i)).toString();
            Hashtable ht = new Hashtable();
            for (int j = 1; j<N; j++) if(tmp.charAt(j)!='0' && tmp.charAt(j) >= tmp.charAt(0) && tmp.charAt(j) <= ed.charAt(0)){
                int rec = recycle(i, j);
                //System.out.println(i +" -> "+ rec);
                if (rec<=B && i<rec && !ht.containsKey(rec)){
                    res ++;
                    ht.put(rec, 1);
                    //System.out.println(i +"\t"+ rec);
                }
            }
        }
        return res;
    }
    

    public static void main(String[] args) throws NumberFormatException, IOException {
        java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(new FileInputStream("C-small-attempt0.in")));
        java.io.BufferedWriter stdout = new java.io.BufferedWriter(new OutputStreamWriter(new FileOutputStream("C-small-attempt0.out")));
        int T = Integer.parseInt(stdin.readLine());
        //T = 3;
        for (int ii=0; ii<T; ii++){
            String str = stdin.readLine();
            String[] words = str.split(" ");
            int res = solve(Integer.parseInt(words[0]), Integer.parseInt(words[1]));
            stdout.write("Case #" + (1+ii) +": " + res+'\n');
        }
        stdout.close();
    }

}
