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 net.jbirch.gcj12qual;

import java.io.FileNotFoundException;
import java.util.Scanner;
import net.jbirch.gcj12qual.util.FileLoader;

/**
 *
 * @author Birch
 */
public class C implements Runnable {

    protected FileLoader inFile;
    protected Scanner in;

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

    public C() {
        inFile = new FileLoader("src\\main\\resources\\C.txt");
    }

    public void run() {
        try {
            in = inFile.getScanner();
            solve();
        } catch (FileNotFoundException fnfe) {
            System.out.println("File not found. Exiting.");
            System.out.println(fnfe);
        }
    }

    //Commence overall magic
    protected void solve() {
        int cases = Integer.valueOf(in.nextLine());
        for (int i = 0; i < cases; i++) {
            System.out.print("Case #" + (i + 1) + ": ");
            solve(in.nextInt(), in.nextInt());
        }
    }

    protected void solve(int low, int high) {
        int digits = (int) Math.log10(low);
        int count=0;

        for (int i = low; i <= high; i++) {
            int[] rotatedThisRound = new int[digits]; // for cases like 1212 - 2121 being counted twice. Sly.
            for (int j = 1; j <= digits; j++) {
                    int rotated = this.rotateInt(i, j);
                    if (rotated < low || rotated > high || i >= rotated || this.contains(rotatedThisRound, rotated)) continue;
                    rotatedThisRound[j - 1] = rotated;
                    count++;
            }
        }

        System.out.println(count);
    }

    protected int rotateInt(int i, int turns) {
        String theGuy = String.valueOf(i);
        String guyThe = theGuy.substring(turns) + theGuy.substring(0, turns);

        if (guyThe.startsWith("0")) return 0; // Force a fail case - rotated number has leading 0 and thus is of different length

        return Integer.valueOf(guyThe);
    }

    protected boolean contains(int[] a, int i) {
        for (int j : a) {
            if (j == i) return true;
        }
        return false;
    }
}
