
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;

public class Recycle
{
	public static void main(String[] args)
	{
/*		Set<Integer> perms = getPermutations(123456);
		
		for(Integer i: perms)
			System.out.println(i);*/
	
		try
		{
			Scanner s = new Scanner(new File("recycle.in"));
			BufferedWriter w = new BufferedWriter(new FileWriter(new File("recycle.out")));
			int numCases = s.nextInt();
			s.nextLine();
			
			for(int n = 1;n <= numCases; n++)
			{
				int A = s.nextInt();
				int B = s.nextInt();
				int count = 0;
				for(int k = A; k <= B; k++)
				{
					count += getNumPairs(k, B);
				}
				
				w.write("Case #" + n + ": " + count + "\n");
			}
			
			w.flush();
			w.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static int getNumPairs(int n, int B)
	{
		Set<Integer> possibles = getPermutations(n);
		int count = 0;
		for(Integer i : possibles)
			if(i > n && i <= B)
				count++;
		return count;
	}
	
	public static Set<Integer> getPermutations(int n)
	{
		Set<Integer> perms = new TreeSet<Integer>();
		char[] digits = String.valueOf(n).toCharArray();
		
		for(int firstPos = 1; firstPos < digits.length; firstPos++)
		{
			String toBuild = "";
			for(int k = 0; k < digits.length; k++)
				toBuild += digits[(firstPos + k) % digits.length];
			perms.add(Integer.parseInt(toBuild));
		}
		return perms;
	}
	

}
package de.at.codejam.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.JFileChooser;

import de.at.codejam.AbstractCodeJamProblemSolver;
import de.at.codejam.util.CodeJamConstants;
import de.at.codejam.util.StatusListener;

public abstract class AbstractCodeJamClient<CASE> implements CodeJamConstants {

	private final CodeJamWindow window = new CodeJamWindow();
	private final CodeJamMainPanel mainPanel = new CodeJamMainPanel();

	private final StatusListener statusListener = mainPanel;

	protected abstract AbstractCodeJamProblemSolver<CASE> getTaskSolver();

	protected abstract String getAssignmentName();

	public void start() {

		if (!DEFAULT_CODE_JAM_DIRECTORY.exists()) {
			DEFAULT_CODE_JAM_DIRECTORY.mkdirs();
		}

		window.setAssignmentName(getAssignmentName());
		window.setContentPane(mainPanel);
		window.setEnabled(true);
		window.setVisible(true);

		final JFileChooser fileChooser = mainPanel.getFileChooser();
		fileChooser.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (e.getActionCommand().equals(JFileChooser.CANCEL_SELECTION)) {
					System.exit(0);
					return;
				}

				File inputFile = fileChooser.getSelectedFile();

				String inputFilename = inputFile.getAbsolutePath();

				int suffixIndex = inputFilename.lastIndexOf(".in");
				String neutralFilenamePart = inputFilename.substring(0,
						suffixIndex);
				String outputFilename = neutralFilenamePart + ".out";

				File outputFile = new File(outputFilename);

				System.out.println("Input: " + inputFilename + ", exists: "
						+ inputFile.exists());
				System.out.println("Output: " + outputFilename + ", exists: "
						+ outputFile.exists());

				if (outputFile.exists()) {
					outputFile.delete();
				}

				try {
					outputFile.createNewFile();
				} catch (IOException ioexception) {
					ioexception.printStackTrace();
				}

				if ((null != inputFile) && (inputFile.exists())) {
					AbstractCodeJamProblemSolver<CASE> taskSolver = getTaskSolver();
					taskSolver.addStatusListener(statusListener);
					taskSolver.solveInputFile(inputFile, outputFile);
				}
			}
		});
	}
}
