import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2

public class C {

	private static String process(Scanner in) {
		int A = in.nextInt();
		int B = in.nextInt();
		int res = 0;
		int len = Integer.toString(A).length();
		for(int n = A; n < B; n++) {
			String str = Integer.toString(n);
			TreeSet<Integer> set = new TreeSet<Integer>();
			for(int i = 1; i < len; i++) {
				int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
				if ( m > n && m <= B && ! set.contains(m) ) {
					set.add(m);
					res++;
				}
			}
		}
		return Integer.toString(res);
	}

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in.available() > 0 ? System.in : 
			new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
		int T = in.nextInt();
		for(int i = 1; i <= T; i++) 
			System.out.format("Case #%d: %s\n", i, process(in));
	}
}

package google.jam;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;

public class RecycledNumbers {
	
	public static void main (String[] args){
		System.out.println("Please, type your input:");
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		boolean checkLines = false;
		int numLines = 0, linesCounter = 0;
		String line;
		String output = "";
		try {
			while((line = stdIn.readLine()) != null){
				if(!checkLines){
					numLines = Integer.parseInt(line);
					checkLines = true;
				}else{
					linesCounter++;
					output += inputToOutput(line, String.valueOf(linesCounter));
				}
				if(linesCounter >= numLines)
					break;
			}	
			System.out.println(output);
		} catch (IOException e) {
			System.out.println("Something went wrong with your input.");
			e.printStackTrace();
		}
	}
	
	public static String inputToOutput(String input, String lineNum){
		TreeSet<String> set = new TreeSet<String>();
		String[] numbers = input.split(" ");
		
		if(numbers.length != 2)
			return "Case #" + lineNum + ": 0\n";
		
		int start = Integer.parseInt(numbers[0]);
		int end = Integer.parseInt(numbers[1]);
		if(start >= end)
			return "Case #" + lineNum + ": 0\n";
		
		int cur = start;
		while(cur <= end){
			for(int i=String.valueOf(cur).length()-1; i>0; i--){
				String number = String.valueOf(cur);
				if(number.charAt(i) == '0')
					continue;
				String newNum = number.substring(i) + number.substring(0, i);
				int newInt = Integer.parseInt(newNum);
				if( newInt > end || newInt < start || newNum.equals(number) )
					continue;
				set.add( (number.compareTo(newNum) < 0)?(newNum+number):(number+newNum) );
			}
			cur++;
		}
		
		return "Case #" + lineNum + ": " + set.size() + "\n";
	}

}
