import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
package template;

import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;

public class TestCaseSolver implements Runnable {

    private ArrayList<TestCase> testCases;
    private int ref;

    public TestCaseSolver(ArrayList<TestCase> tcs, int ref) {
        testCases = tcs;
        this.ref = ref;
    }

    public TestCaseSolver(TestCase tc, int ref) {
        ArrayList<TestCase> tcs = new ArrayList<>();
        tcs.add(tc);
        testCases = tcs;
        this.ref = ref;
    }

    public int getRef() {
        return ref;
    }

    @Override
    public void run() {
        for (TestCase tc : testCases) {
            long startTime = System.nanoTime();
            solve(tc);
            long duration = System.nanoTime() - startTime;
            double secs = (double)duration / (1000000000d);
            tc.setTime(secs);
            System.out.println("Thread " + ref + " solved testcase " + tc.getRef() + " in " + String.format("%.2f", secs) + " secs.");
        }
    }

    private void solve(TestCase tc) {
        ArrayList<Integer> a_b = tc.getIntegerList("a_b");
        int A = a_b.get(0);
        int B = a_b.get(1);
        int count = 0;
        for (int i = A; i <= B; i++) {
            ArrayList<Integer> digs = Utils.splitToDigits(i);
            int l = digs.size();
            Set<Integer> solns = new HashSet<>();
            for (int r = 1; r < l; r++) {
                int rec = recombine(digs, r);
                if (valid(digs, r) && rec <= B) {
                    //System.out.println(digs + " " + r);
                    solns.add(new Integer(rec));
                }
            }
            count += solns.size();
        }
        
        
        tc.setSolution(new Integer(count));
    }
    
    private boolean valid(ArrayList<Integer> digits, int startRotation) {
        if (digits.get(startRotation).intValue() == 0) {return false;}
        int len = digits.size();
        for (int origLoc = 0; origLoc < len; origLoc++) {
            int rotLoc = (origLoc + startRotation) % len;
            int origDig = digits.get(origLoc);
            int rotDig = digits.get(rotLoc);
            if (rotDig > origDig) {return true;}
            if (rotDig < origDig) {return false;}
        }
        return false;
        
    }
    
    private int recombine(ArrayList<Integer> digs, int start) {
        int tot = 0;
        for (int i = 0; i < digs.size(); i++) {
            int loc = (i + start) % digs.size();
            tot += digs.get(loc).intValue() * (int)(Math.pow(10d, (double)(digs.size() - i - 1)));
        }
        return tot;
    }
}
