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;
import java.util.logging.Level;
import java.util.logging.Logger;


public class QC {
    public static void main(String[] args) {
        try{
            Scanner sc = new Scanner(new File("C-small-attempt0.in"));    
            BufferedWriter bw = new BufferedWriter(new FileWriter(new File("output.out"))); 
            int t = sc.nextInt();
            for(int i=0;i<t;i++){
                int a = sc.nextInt();              
                int b = sc.nextInt();
                int r = 0;
                if(a>=100 && a<1000){
                    for(int p=1;p<10;p++){
                        for(int q=0;q<10;q++){
                            if(p==q)continue;
                            int e = 0,m = 0;
                            m = 100*q+10*p+p; if(m>=a && m<=b) e++;
                            m = 100*p+10*q+p; if(m>=a && m<=b) e++;
                            m = 100*p+10*p+q; if(m>=a && m<=b) e++;
                            if(e==3) r += 3;
                            else if(e==2) r += 1;
                        }
                    }
                    for(int p=0;p<10;p++){
                        for(int q=p+1;q<10;q++){
                            for(int s=q+1;s<10;s++){
                                int e = 0,m = 0;
                                m = 100*p+10*q+s; if(m>=a && m<=b) e++;
                                m = 100*q+10*s+p; if(m>=a && m<=b) e++;
                                m = 100*s+10*p+q; if(m>=a && m<=b) e++;
                                if(e==3) r += 3;
                                else if(e==2) r += 1;
                                
                                e = 0;
                                m = 100*p+10*s+q; if(m>=a && m<=b) e++;
                                m = 100*s+10*q+p; if(m>=a && m<=b) e++;
                                m = 100*q+10*p+s; if(m>=a && m<=b) e++;
                                if(e==3) r += 3;
                                else if(e==2) r += 1;
                            }
                        }
                    }
                }
                else if(a>=10){
                    for(int p=1;p<10;p++){
                        for(int q=p+1;q<10;q++){
                            if(p*10+q>=a && p*10+q<=b && q*10+p>=a && q*10+p<=b) r++;
                        }
                    }
                }
                bw.write("Case #"+String.valueOf(i+1)+": ");
                bw.write(String.valueOf(r));
                bw.newLine();
                bw.flush();
            }
            bw.close();

        } catch (Exception ex) {
            Logger.getLogger(QA.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
