/*
 * 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;
    }
}



import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;



public class RecycledNumbers{
	public static void main(String[] args) throws IOException{
		String testCases;
		BufferedReader brTestCases = new BufferedReader(new InputStreamReader(System.in));
		File inFile = new File("C:/Users/AbhilashR/Downloads/C-small-attempt0.in" ); 
		Scanner sc = new Scanner(inFile);
		//testCases = (String)brTestCases.readLine();
		testCases = sc.nextLine();
		Integer noOfTestCases = null;
		try{
			noOfTestCases = Integer.parseInt(testCases);
		}catch (NumberFormatException e){
			System.out.println("The entered value is not a Number");
		}
		ArrayList<String> inputData = new ArrayList<String>();
		for(int i =0;i<noOfTestCases;i++){
			brTestCases = new BufferedReader(new InputStreamReader(System.in));
			//testCases = (String)brTestCases.readLine();
			testCases = sc.nextLine();
			inputData.add(testCases);
		}
		
		ArrayList<Object[]> inputDataObj = new ArrayList<Object[]>();
		for(int i =0;i<inputData.size();i++){
			inputDataObj.add(inputData.get(i).split(" "));
		}
		Writer output = null;
		File outFile = new File("C:/Users/AbhilashR/Downloads/outPut.txt" );
		output = new BufferedWriter(new FileWriter(outFile));
		String text = "";
		for(int i =0;i < inputDataObj.size();i++){
			Object[] dataObj = inputDataObj.get(i);
			int integerA = Integer.parseInt((String)dataObj[0]);
			int integerB = Integer.parseInt((String)dataObj[1]);
			int recycledNumbers = getRecycledNumbers(integerA, integerB);
			text = "Case #"+(i+1)+": "+recycledNumbers+"\r\n";
			output.write(text);
			output.flush();
			
		}
		//output.write(text);
		output.close();
	}
	public static Integer getRecycledNumbers(Integer a,Integer b){
		Integer noOfRecycledNumbers = 0;
		Integer sampleN =a;
		
		Integer numberOfDigits = 0;
		numberOfDigits = Integer.toString(a).length();
		for(sampleN =a; sampleN < b ;sampleN++){
			Integer sampleM = sampleN;
			Set<Integer> tempSet = new HashSet<Integer>();
			for(int j =0; j< numberOfDigits; j++){
				int currentSize = Integer.toString(sampleM).length();
				if(currentSize==numberOfDigits){
					sampleM = Integer.parseInt(Integer.toString(sampleM%10)+Integer.toString(sampleM/10));
				}else{
					String formingSampleM = Integer.toString(sampleM%10);
					for(int k =0;k<numberOfDigits-currentSize;k++){
						formingSampleM = formingSampleM+"0";
					}
					formingSampleM = formingSampleM+Integer.toString(sampleM/10);
					sampleM = Integer.parseInt(formingSampleM);
				}
				if(sampleN<sampleM && sampleM<=b){
					tempSet.add(sampleM);
				}
			}	
			noOfRecycledNumbers += tempSet.size();
		}
		if(noOfRecycledNumbers>0){
			return noOfRecycledNumbers;
		}
		return 0;
	}
	
}