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 problem.c;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;

import org.apache.commons.io.FileUtils;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

public class RecycledNumbers {

	private static final String INPUT_FILE = "C-small-attempt0.in";

	public static void main(String[] args) throws IOException {
		File inputFile = new File(INPUT_FILE);
		List<String> inputLines = FileUtils.readLines(inputFile);
		Integer.parseInt(inputLines.remove(0));
		List<String> outputLines = Lists.newArrayList();
		for (int k = 0; k < inputLines.size(); k++) {
			String line = inputLines.get(k);
			int seperator = line.indexOf(' ');
			int a = Integer.valueOf(line.substring(0, seperator));
			int b = Integer.valueOf(line.substring(seperator + 1));
			Set<String> matches = Sets.newHashSet();
			for (int currentNumber = a; currentNumber < b; currentNumber++) {
				String stringA = String.valueOf(currentNumber);
				for (int j = 1; j < stringA.length(); j++) {
					String begin = stringA.substring(j);
					String end = stringA.substring(0, j);
					int generatedNumToCheck = Integer.valueOf(begin + end);
					if (generatedNumToCheck <= b && generatedNumToCheck >= a
							&& generatedNumToCheck != currentNumber
							&& generatedNumToCheck > currentNumber) {
						matches.add(currentNumber + " - " + generatedNumToCheck);
					}
				}
			}
			outputLines.add("Case #" + (k + 1) + ": " + matches.size());
		}
		System.out.println(outputLines);
		FileUtils.writeLines(new File("generated-recycled-numbers-output.txt"), outputLines);
	}

}
