import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;


public class GoogleC {
	public String szamol(String input){
		String result="";
		String a=input;
		Integer min=Integer.parseInt(a.substring(0,a.indexOf(' ')));
		a=a.substring(a.indexOf(' ')+1);
		Integer max=Integer.parseInt(a);
		Long count=0l;
		for(Integer i=min; i<=max; i++){
			String e1=i.toString();
			Set<Integer> db=new HashSet<Integer>(); 
			for (int j=1; j<e1.length();j++){
				
				String e2=e1.substring(j)+e1.substring(0,j);
				Integer k=Integer.parseInt(e2);
				if (k>i && k<=max){
					db.add(k);
					//System.out.println(e1+"\t"+e2);
				}
				
			}
			count+=db.size();
		}
		
		return count.toString();
	}
	public static void main(String[] args) {
		GoogleC a=new GoogleC();
		//String filename="input.txt";
		//String filename="C-small-attempt0.in";
		String filename="C-large.in";
		String thisLine;
		try {
			BufferedReader br = new BufferedReader(new FileReader(filename));
			BufferedWriter bw= new BufferedWriter(new FileWriter(filename+".out"));
			thisLine=br.readLine();
			Integer tnum=Integer.parseInt(thisLine);
		     for(int i=0;i<tnum;i++) { // while loop begins here
		    	 	thisLine=br.readLine();
		           System.out.println(thisLine);
		           System.out.println("Case #"+(i+1)+": "+a.szamol(thisLine)+"\n");
		           bw.write("Case #"+(i+1)+": "+a.szamol(thisLine)+"\n");
		         } // end while 
		        // end try
		     br.close();
		     bw.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


	}

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package problem.c;
import java.util.Scanner;
import java.io.*;

/**
 *
 * @author Jason
 */
public class ProblemC {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner input = new Scanner(System.in);
        System.out.println("Enter name of input file: ");
        File inputFile = new File(input.next());
        File outputFile = new File("output.txt");
        Scanner file = null;
        PrintWriter output = null;
        while(file == null)
        {
            try{
                file = new Scanner(inputFile);
                output = new PrintWriter(outputFile);
            }
            catch(Exception E){
                System.out.println("invalid file");
            }
        }
        int cases = file.nextInt();
        file.nextLine();
        for (int i = 0; i < cases;)
        {
            int pairs = 0;
            int A = file.nextInt();
            int B = file.nextInt();
            for(;A < B;A++)
            {
                int[] newA = null;
                if (A>999999)
                    newA = new int[7];
                else if (A>99999)
                    newA = new int[6];
                else if (A>9999)
                    newA = new int[5];
                else if (A>999)
                    newA = new int[4];
                else if (A>99)
                    newA = new int[3];
                else if (A>9)
                    newA = new int[2];
                else
                    newA = new int[1];
                int tempA = A;
                for(int j = newA.length-1; j >= 0;j--)
                {
                    newA[j] = tempA % 10;
                    tempA = tempA / 10;
                }
                int[] savedFound = {0, 0, 0, 0, 0, 0};
                int foundIterator = 0;
                for(int j = 0; j < newA.length-1; j++)
                {
                    int temp = newA[newA.length-1];
                    for(int k = 0; k < newA.length; k++)
                    {
                        int temp2 = newA[k];
                        newA[k] = temp;
                        temp = temp2;
                    }
                    temp = 0;
                    for(int k =  newA.length-1, tens = 1; k >= 0;k--,tens*=10)
                    {
                        temp += newA[k]*tens;
                    }
                    if (temp > A && temp <= B && temp != savedFound[0] && temp
                            != savedFound[1] && temp != savedFound[2] && temp
                            != savedFound[3] && temp != savedFound[4] && temp
                            != savedFound[5] )
                    {
                        pairs++;
                        savedFound[foundIterator++] = temp;
                    }
                }
            }
            output.println("Case #" + ++i + ": " + pairs);
        }
        output.close();
    }
}