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 CodeJam;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;

public class C {

	/**
	 * @param args
	 */
	static Scanner scan = new Scanner(System.in);
	static BufferedReader brscan = new BufferedReader(new InputStreamReader(
			System.in));
	static PrintWriter pw;
	static StringBuilder[] permutation = new StringBuilder[2222222];
	static StringBuilder sbuild = new StringBuilder();

	public static void main(String[] args) throws FileNotFoundException {
		pw = new PrintWriter(new File("output-C.txt"));
		// TODO Auto-generated method stub

		GeneratePermutation();

		int tc = scan.nextInt();
		int from, to;

		for (int x = 1; x <= tc; x++) {
			int count = 0;
			from = scan.nextInt();
			to = scan.nextInt();
			for (int n = from; n < to; n++) {

				count += (SameString(permutation[n], n + 1, to));
				
			}
			pw.println("Case #" + x + ": " + count);
		}
		//pw.println(SameStringB(new StringBuilder("2212"), new StringBuilder("2221")));
		pw.flush();
		pw.close();
		
	}

	public static boolean SameStringB(StringBuilder ac, StringBuilder bc) {
		StringBuilder a = new StringBuilder(ac);
		StringBuilder b = new StringBuilder(bc);
		int length = a.length();
		for (int n=0; n<length; n++) {
			if (a.charAt(0)!=0 && a.toString().equals(b.toString())) {
				
				return true;
			} 
			// process //
			char temp = a.charAt(0);
			a.append(temp);
			a.deleteCharAt(0);
		}
		return false;
	}
	
	static HashSet<Integer> hset = new HashSet<Integer>(2000);
	public static int SameString(StringBuilder ac, int min, int max) {
		StringBuilder a = new StringBuilder(ac);
		hset.clear();
		int length = a.length();
		int normal = Integer.parseInt(a.toString());
		
		int count = 0;
		for (int n = 0; n < length-1; n++) {

			a.append(a.charAt(0));
			a.deleteCharAt(0);
			if (a.charAt(0) != '0') {
				int now = Integer.parseInt(a.toString());
				if (now >= min && now <= max && hset.contains(now)==false) {
					hset.add(now);
					
					count++;
				}
			}
		}
		
		
		return count;
	}

	public static void GeneratePermutation() {
		for (int n = 1; n < 2222222; n++) {
			permutation[n] = new StringBuilder(n + "");
		}
	}
}
