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 gcjqual;

import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author greg
 */
public class GCJQual3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        GCJQual3 g = new GCJQual3();
        g.run();
    }

    private void run() {
        BufferedReader br = null;
        BufferedWriter bw = null;
        String eachLine;
        int count = 1;
        try {
            br = new BufferedReader(new FileReader("input3.txt"));
//            bw = new BufferedWriter(new OutputStreamWriter(System.out));
            bw = new BufferedWriter(new FileWriter("output3.txt"));
            String numTests = br.readLine();
            System.out.println(numTests);
            while ((eachLine = br.readLine()) != null) {
                bw.write("Case #" + count + ": ");
                bw.write(solve(eachLine));
                bw.newLine();
                count++;
            }
        } catch (IOException ex) {
            ex.printStackTrace();
            Logger.getLogger(GCJQual3.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                bw.close();
                br.close();
            } catch (IOException ex) {
                Logger.getLogger(GCJQual3.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }

    private String solve(String eachLine) {
        String[] params = eachLine.split(" ");
        int A = Integer.valueOf(params[0]);
        int B = Integer.valueOf(params[1]);
        int recycledCount = 0;
        
        for (int n=A; n<=B; n++) {
            Set<Integer> possible = getRecycled(n);
            for (int m:possible) {
                if (m <= B) {
                    recycledCount++;
                }
            }
        }
        return "" + recycledCount;
    }

    private Set<Integer> getRecycled(int n) {
        Set<Integer> possible = new HashSet<Integer> ();
        int shift = 2;
        if ( n > 11 ) { // no single or 10 or 11
            if ( n >= 1000000) {
                shift = 7;
            } else if ( n >= 100000) {
                shift = 6;
            } else if ( n >= 10000) {
                shift = 5;
            } else if ( n >= 1000) {
                shift = 4;
            } else if ( n >= 100 ) {
                shift = 3;
            }
            int newNum = n;
            for ( int i =0; i< shift-1; i++) {
                int last = newNum % 10;
                newNum = (int) (newNum / 10 + (Math.pow(10, shift-1)*last));
                if ( newNum > n ) {
                    possible.add(newNum);
                }
            }
        }
        // Cache possible
        return possible;
    }
    
}

