/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package recyclednumbers;

import java.util.HashSet;

/**
 *
 * @author vandit
 */
public class RecycleNumbers {

    private HashSet<String> numbers = new HashSet<String>();
    private HashSet<String> initialTempNumbers = new HashSet<String>();
    private HashSet<String> finalTempNumbers = new HashSet<String>();

    HashSet<Pair> numberPairs = new HashSet<Pair>();


    private void findRecycledNumbers(int start, int end, int places) {


        for (int i = start; i <= end; i++) {
            String initialNumber = Integer.toString(i);
            //if (!(numbers.contains(initialNumber) || finalTempNumbers.contains(initialNumber))) {

                StringBuffer tempNumber = new StringBuffer(initialNumber);
                int len = tempNumber.length();
                int startIndexToMove = len - places;
                String tempString = tempNumber.substring(startIndexToMove);
                if ((places == 1 && tempString.equals("0")) || tempString.charAt(0) == '0') {
                    continue;
                }
                tempNumber.delete(startIndexToMove, len);
                String finalTempNumber = tempString + tempNumber.toString();

                if (! (finalTempNumber.equals(initialNumber) || Integer.parseInt(finalTempNumber) > end || Integer.parseInt(finalTempNumber) < Integer.parseInt(initialNumber))) {
                    numbers.add(initialNumber);
                    finalTempNumbers.add(finalTempNumber);
                    Pair pair = new Pair(finalTempNumber,initialNumber);
                    numberPairs.add(pair);
                }
            }

        

    }

    public HashSet<Pair> findAllRecycledNumbers(int start, int end) {
        int length = Integer.toString(start).length();
        for (int i = 1; i < length; i++) {
            findRecycledNumbers(start, end, i);
        }
        return numberPairs;
    }
}

package Qualifier;

import java.io.*;
import java.util.*;

public class C_Small {
	private static Scanner in;
	private static PrintWriter out;
    private static String testCase = "C-small";

    public static void main(String[] args) throws Exception {
        Locale.setDefault(Locale.ENGLISH);
        out = new PrintWriter(new FileOutputStream(testCase + ".out"));
        in = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(testCase + ".in"))));
        
        int tests = in.nextInt();
        in.nextLine();
    	
        for (int t = 1; t <= tests; ++t) {
            out.print("Case #" + t + ": ");
            new C_Small().solve();
        }
        in.close();
        out.close();
    }

    void solve() throws Exception {
    	int A = in.nextInt();
    	int B = in.nextInt();
    	long result = 0; 
    	if(B < A || String.valueOf(A).trim().length() != String.valueOf(B).trim().length()){
    		return;
    	}
    	
    	for(int n=A; n<=B; n++){
    		String nString = String.valueOf(n);
    		int length = nString.length();
    		for(int j = 1; j < length; j++){
    			String c = nString.substring(j, length) + nString.substring(0 , j);
    			int mCase = Integer.parseInt(c);
    			if(mCase >= A && mCase <= B && mCase > n){
    				result++;
    			}
    		}
    	}
  
    	out.println(result);
    }
}
