/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package recyclednumbers;

import java.util.HashSet;

/**
 *
 * @author vandit
 */
public class RecycleNumbers {

    private HashSet<String> numbers = new HashSet<String>();
    private HashSet<String> initialTempNumbers = new HashSet<String>();
    private HashSet<String> finalTempNumbers = new HashSet<String>();

    HashSet<Pair> numberPairs = new HashSet<Pair>();


    private void findRecycledNumbers(int start, int end, int places) {


        for (int i = start; i <= end; i++) {
            String initialNumber = Integer.toString(i);
            //if (!(numbers.contains(initialNumber) || finalTempNumbers.contains(initialNumber))) {

                StringBuffer tempNumber = new StringBuffer(initialNumber);
                int len = tempNumber.length();
                int startIndexToMove = len - places;
                String tempString = tempNumber.substring(startIndexToMove);
                if ((places == 1 && tempString.equals("0")) || tempString.charAt(0) == '0') {
                    continue;
                }
                tempNumber.delete(startIndexToMove, len);
                String finalTempNumber = tempString + tempNumber.toString();

                if (! (finalTempNumber.equals(initialNumber) || Integer.parseInt(finalTempNumber) > end || Integer.parseInt(finalTempNumber) < Integer.parseInt(initialNumber))) {
                    numbers.add(initialNumber);
                    finalTempNumbers.add(finalTempNumber);
                    Pair pair = new Pair(finalTempNumber,initialNumber);
                    numberPairs.add(pair);
                }
            }

        

    }

    public HashSet<Pair> findAllRecycledNumbers(int start, int end) {
        int length = Integer.toString(start).length();
        for (int i = 1; i < length; i++) {
            findRecycledNumbers(start, end, i);
        }
        return numberPairs;
    }
}

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;

public class SpeakingInTongues {

	static int caseNumber;
	static int totalCases;
	static HashMap<Character, Character> map = new HashMap(36); 
	//Uses 36 so the map doesn't rebuild to keep the load factor below .75 with 26 maps

	public static void main(String[] args) throws Exception {

		caseNumber = 1;
	

		File fileIn = new File("C:\\GCJ\\SpeakingInTongues\\A-small-attempt1.in");
		FileInputStream fileInputStream = null;
		BufferedInputStream inputStream = null;
		BufferedReader reader = null;
		Writer out;

		String newLine = System.getProperty("line.separator");

		String fileOutPath = "C:\\GCJ\\SpeakingInTongues\\outputSmall2.txt";
		File fileOut = new File(fileOutPath);
		if (!fileOut.createNewFile()) {
			fileOut.delete();
			fileOut.createNewFile();
		}

		out = new OutputStreamWriter(new FileOutputStream(fileOutPath), "US-ASCII");
		StringBuilder builder = new StringBuilder();

		map.put('a', 'y');
		map.put('b', 'h');
		map.put('c', 'e');
		map.put('d', 's');
		map.put('e', 'o');
		map.put('f', 'c');
		map.put('g', 'v');
		map.put('h', 'x');
		map.put('i', 'd');
		map.put('j', 'u');
		map.put('k', 'i');
		map.put('l', 'g');
		map.put('m', 'l');
		map.put('n', 'b');
		map.put('o', 'k');
		map.put('p', 'r');
		map.put('q', 'z'); //Not given to us in the sample. Either Q or Z, the other not given
		map.put('r', 't');
		map.put('s', 'n');
		map.put('t', 'w');
		map.put('u', 'j');
		map.put('v', 'p');
		map.put('w', 'f');
		map.put('x', 'm');
		map.put('y', 'a');
		map.put('z', 'q'); //Not given to us in the sample. Either Z or Q, the other not given
		map.put(' ', ' ');
		
		try {
			fileInputStream = new FileInputStream(fileIn);

			// Here BufferedInputStream is added for fast reading.
			inputStream = new BufferedInputStream(fileInputStream);
			reader = new BufferedReader(new InputStreamReader(inputStream));

			totalCases = Integer.parseInt(reader.readLine());
			while (caseNumber <= totalCases) {
				builder.append(handleTestCase(reader));
				builder.append(newLine);
				caseNumber++;
			}

			// dispose all the resources after using them.
			fileInputStream.close();
			inputStream.close();
			reader.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.print(builder.toString());
		out.write(builder.toString());
		out.close();
	}

	public static String handleTestCase(BufferedReader reader) throws Exception {
		String line = reader.readLine();
		char[] chars = line.toCharArray();
		for (int i = 0; i < chars.length; i++){
			chars[i] = map.get(chars[i]);
		}
		return "Case #"+caseNumber+": "+String.valueOf(chars);
	}
}
