import java.io.*;
import java.util.*;

public class TestGen {

	PrintWriter out;
	Random rnd;
	int tNumber;

	void printTest(String s) throws IOException {
		if (tNumber < 10)
			out = new PrintWriter("../tests/0" + tNumber);
		else
			out = new PrintWriter("../tests/" + tNumber);
		tNumber++;
		out.println(s);
		out.close();
	}

	public void solve() throws IOException {
		out = new PrintWriter("../preliminary/01");
		out.println("abcd");
		out.close();
		out = new PrintWriter("../preliminary/02");
		out.println("abab");
		out.close();
		tNumber = 1;
		rnd = new Random(31);
		printTest("ab");
		printTest("xx");
		for (int x : new int[] { 100, 5_000, 100_000 }) {
			printTest(genPal(x));
			printTest(genPal(x - 1));
			printTest(genRandomSwap(x, 1));
			printTest(genRandomSwap(x - 1, 1));
			printTest(genSwapWithCenter(x - 1));
			printTest(genRandomChange(x - 1));
			printTest(genRandomChange(x));
			printTest(genRandomSwap(x, 2));
			printTest(genRandomSwap(x - 1, 2));
			printTest(genCenterChange(x));
			printTest(genEndChange(x - 1));
		}
	}

	private String genEndChange(int i) {
		char[] c = genPal(i).toCharArray();
		c[c.length - 1] = (char) ('a' + rnd.nextInt(26));
		return new String(c);
	}

	private String genCenterChange(int i) {
		char[] c = genPal(i).toCharArray();
		c[c.length / 2] = (char) ('a' + rnd.nextInt(26));
		return new String(c);
	}

	private String genRandomChange(int i) {
		char[] c = genPal(i).toCharArray();
		c[rnd.nextInt(c.length)] = (char) ('a' + rnd.nextInt(26));
		return new String(c);
	}

	private String genSwapWithCenter(int i) {
		char[] c = genPal(i).toCharArray();
		int a = rnd.nextInt(c.length);
		int b = c.length / 2;
		char t = c[a];
		c[a] = c[b];
		c[b] = t;
		return new String(c);
	}

	private String genRandomSwap(int x, int i) {
		char[] c = genPal(x).toCharArray();
		for (int j = 0; j < i; j++) {
			int a = rnd.nextInt(c.length);
			int b = rnd.nextInt(c.length);
			char t = c[a];
			c[a] = c[b];
			c[b] = t;
		}
		return new String(c);
	}

	private String genPal(int x) {
		x = x - rnd.nextInt(x / 10) * 2;
		char[] c = new char[x];
		for (int i = 0; i < x / 2 + x % 2; i++) {
			c[i] = (char) ('a' + rnd.nextInt(26));
			c[x - i - 1] = c[i];
		}
		return new String(c);
	}

	public void run() {
		try {

			solve();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new TestGen().run();
	}
}
