import java.io.*;

class code1
{
	public static void main(String args[]) throws Exception 
	{
		File ii = new File ("C-small-attempt1.in");
		FileInputStream fis = new FileInputStream(ii);
		BufferedReader  br = new BufferedReader(new InputStreamReader (fis));
		int cases = Integer.parseInt(br.readLine());
		FileOutputStream fout = new FileOutputStream ("output.txt");
		DataOutputStream dout = new DataOutputStream (fout);
		int total=0;
		for(int i=0;i<cases;i++){
		String temp = br.readLine();
		String parts [] = temp.split(" ");
		int lower = Integer.parseInt(parts[0]);
		int upper = Integer.parseInt(parts[1]);
		System.out.println(lower+" "+upper);
		
		for(int j=lower;j<=upper;j++)
		{
			int abc = j;int length=0;
			if(j<10)continue;
			while (abc!=0){abc/=10;length++;}
			abc=j;
			for(int m=0;m<length-1;m++){
				int shift = abc%10;
				abc=abc/10;
				System.out.println("hi "+j);
				abc=abc+shift*power(10,length-1);
				if(abc<=upper&&shift!=0&&abc>j)total++;
				System.out.println(total);
			}
		}
 		dout.writeBytes("Case #"+(i+1)+ ": "+total+"\n");
 		total=0;
		}//for close
		
	}

	private static int power(int i, int j) {
		int no=1;
		for(int a=0;a<j;a++){no=10*no;}
		return no;
	}
}
package QualificationRound2012.C.RecycledNumbers;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class RecycledNumbers {
	static final String _DIR = "src/QualificationRound2012/C/RecycledNumbers/";
	static final String INPUT_FILE = _DIR + "C-small-attempt0.in";
	static final String OUTPUT_FILE = INPUT_FILE + ".out";

	private static int algorithm(final String line) {
		int distinctPairs = 0;
		final String[] split = line.split(" ");
		final String A_str = split[0];
		final String B_str = split[1];
		final int A = Integer.parseInt(A_str);
		final int B = Integer.parseInt(B_str);

		// A â¤ n < m â¤ B
		for (int m = A; m <= B; m++) {
			for (int n = m + 1; n <= B; n++) {
				// System.out.print(A + " â¤ " + m + " < " + n + " â¤ " + B);
				if (isRecycled(m, n)) {
					// System.out.println(" --> YES!");
					distinctPairs++;
				} else {
					// System.out.println();
				}
			}
		}
		return distinctPairs;
	}

	private static boolean isRecycled(final int m, final int n) {
		final String mString = String.valueOf(m);
		final String nString = String.valueOf(n);
		final int length = mString.length();
		String rot = mString;
		for (int i = 0; i < length; i++) {
			if (rot.equals(nString)) {
				return true;
			}
			rot = rotate(rot);
		}
		return false;
	}

	public static void main(final String args[]) throws IOException {
		final BufferedWriter writer = new BufferedWriter(new FileWriter(OUTPUT_FILE));
		final BufferedReader reader = new BufferedReader(new FileReader(new File(INPUT_FILE)));

		long timeStart = System.currentTimeMillis();

		String line;
		int testcase = 0;
		while ((line = reader.readLine()) != null) {
			if (testcase != 0) {
				System.out.println("Case #" + testcase + ": " + algorithm(line));
			}
			testcase++;
		}

		long timeEnd = System.currentTimeMillis();
		System.out.println(timeEnd - timeStart + " millis");

	}

	private static String rotate(final String number) {
		final char[] numberArray = number.toCharArray();
		final char last = numberArray[numberArray.length - 1];
		return last + number.substring(0, number.length() - 1);
	}
}
