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

public class Gen {

	static int done = 0;

	static final Random rand = new Random(556668949239L);

	static final int MAX_LENGTH1 = 1000;
	static final int MAX_LENGTH2 = (int) 1e5;

	static final int MAX_ALPHA1 = 2;
	static final int MAX_ALPHA2 = 26;

	final static String ALPHA = "abcdefghijklmnopqrstuvwxyz";

	static void print(String s, String t) throws IOException {
		done++;
		System.err.println(done);
		PrintWriter out;
		if (done < 10)
			out = new PrintWriter("../tests/0" + String.valueOf(done));
		else
			out = new PrintWriter("../tests/" + String.valueOf(done));

		out.println(s);
		out.println(t);
		out.close();
	}

	static void genSimple() throws IOException {
		PrintWriter out;
		out = new PrintWriter("../preliminary/01");
		out.println("abcabca");
		out.println("abcda");
		out.close();

		out = new PrintWriter("../preliminary/02");
		out.println("ccba");
		out.println("accbbaa");
		out.close();
	}

	static String genRand(int len, int size) throws IOException {
		len = randLength2(len) + 3;
		StringBuilder tmp = new StringBuilder();
		for (int i = 0; i < len; i++)
			tmp.append(ALPHA.charAt(rand.nextInt(size)));
		return tmp.toString();
	}

	static String genFill(int len, char c) throws IOException {
		len = randLength2(len);
		StringBuilder tmp = new StringBuilder();
		for (int i = 0; i < len; i++)
			tmp.append(c);
		return tmp.toString();
	}

	static String genSpecialString(int len, int size) throws IOException {
		len = randLength2(len);
		StringBuilder tmp = new StringBuilder();
		char ma = 'a';
		for (int i = 0; i < len - 1; i++) {
			char t = ALPHA.charAt(rand.nextInt(size));
			if (t > ma)
				ma = t;
			tmp.append(t);
		}
		tmp.append(ma);
		return tmp.toString();
	}

	static String genSortString(int len, int size) throws IOException {
//		len = randLength2(len);
		StringBuilder tmp = new StringBuilder();
		int tek = 0;
		for (int i = 0; i < size - 1; i++) {
			int cur = rand.nextInt(len / size / 2 + 1) + 1;
			tek += cur;
			for (int j = 0; j < cur; j++)
				tmp.append(ALPHA.charAt(i));
		}
		for (int i = tek; i < len; i++)
			tmp.append(ALPHA.charAt(size - 1));
		return tmp.toString();
	}

	static String genSortString2(int len, int size) throws IOException {
//		len = randLength2(len);
		String s = genSortString(len, size);
		StringBuilder tmp = new StringBuilder(s);
		tmp.reverse();
		return tmp.toString();
	}

	static void emptyAns(int len1, int len2, int size) throws IOException {
		String a[] = new String[2];
        a[0] = "";
        a[1] = "";
		for (int i = 0; i < size / 2; i++) {
			a[0] += ALPHA.charAt(2 * i);
			a[1] += ALPHA.charAt(2 * i + 1);
		}
		StringBuilder tmp1 = new StringBuilder();
		for (int i = 0; i < len1; i++)
			tmp1.append(a[0].charAt(rand.nextInt(a[0].length())));

		StringBuilder tmp2 = new StringBuilder();
		for (int i = 0; i < len1; i++)
			tmp2.append(a[1].charAt(rand.nextInt(a[1].length())));

		print(tmp1.toString(), tmp2.toString());
	}

	static int randLength(int len) throws IOException {
		return len / 2 + rand.nextInt(len / 2);
	}

	static int randLength2(int len) throws IOException {
		return rand.nextInt(len) + 1;
	}

	public static void main(String[] args) throws IOException {
		boolean f = (new File("../preliminary")).mkdir();
		f = new File("../tests").mkdir();

		genSimple();

		done = 0;
		// First test case (length <= 1000, alpha = 2)
		emptyAns(MAX_LENGTH1, MAX_LENGTH1, MAX_ALPHA1);
		print(genRand(10, MAX_ALPHA1),
				genRand(10, MAX_ALPHA1));
		print(genRand(100, MAX_ALPHA1), genFill(100, 'b'));
		print(genSortString(MAX_LENGTH1, MAX_ALPHA1),
				genSortString2(MAX_LENGTH1, MAX_ALPHA1));
		print(genSpecialString(MAX_LENGTH1, MAX_ALPHA1),
				genRand(MAX_LENGTH1, MAX_ALPHA1));

		print(genSpecialString(MAX_LENGTH1, MAX_ALPHA1),
				genSortString(MAX_LENGTH1, MAX_ALPHA1));
		print(genFill(10, 'a'), genFill(10, 'a'));
		print(genSortString(100, MAX_ALPHA1),
				genRand(300, MAX_ALPHA1));
		print(genSortString2(65, MAX_ALPHA1),
				genRand(50, MAX_ALPHA1));
		print(genRand(MAX_LENGTH1, MAX_ALPHA1),
				genRand(MAX_LENGTH1, MAX_ALPHA1));

		// Second test case (length <= 100000, alpha = 2);
		emptyAns(MAX_LENGTH2, MAX_LENGTH2, MAX_ALPHA1);
		print(genRand(MAX_LENGTH2, MAX_ALPHA1),
				genRand(MAX_LENGTH2, MAX_ALPHA1));
		print(genRand(MAX_LENGTH2, MAX_ALPHA1), genFill(MAX_LENGTH2, 'b'));
		print(genSortString(MAX_LENGTH2, MAX_ALPHA1),
				genSortString2(MAX_LENGTH2, MAX_ALPHA1));
		print(genSpecialString(MAX_LENGTH2, MAX_ALPHA1),
				genRand(MAX_LENGTH2, MAX_ALPHA1));

		print(genSpecialString(MAX_LENGTH2, MAX_ALPHA1),
				genSortString(MAX_LENGTH2, MAX_ALPHA1));
		print(genFill(MAX_LENGTH2, 'a'), genFill(MAX_LENGTH2, 'a'));
		print(genSortString(MAX_LENGTH2, MAX_ALPHA1),
				genRand(MAX_LENGTH2, MAX_ALPHA1));
		print(genSortString2(MAX_LENGTH2, MAX_ALPHA1),
				genRand(MAX_LENGTH2, MAX_ALPHA1));
		print(genRand(MAX_LENGTH2, MAX_ALPHA1),
				genRand(MAX_LENGTH2, MAX_ALPHA1));

		// Third test case (length <= 1000, alpha = 26)
		emptyAns(MAX_LENGTH1, MAX_LENGTH1, MAX_ALPHA2);
		print(genRand(MAX_LENGTH1, MAX_ALPHA2),
				genRand(MAX_LENGTH1, MAX_ALPHA2));
		print(genRand(150, MAX_ALPHA2), genFill(50, 'z'));
		print(genSortString(MAX_LENGTH1, MAX_ALPHA2),
				genSortString2(MAX_LENGTH1, MAX_ALPHA2));
		print(genSpecialString(10, MAX_ALPHA2),
				genRand(15, MAX_ALPHA2));

		print(genSpecialString(150, MAX_ALPHA2),
				genSortString(85, MAX_ALPHA2));
		print(genFill(MAX_LENGTH1, 'z'), genFill(MAX_LENGTH1, 'z'));
		print(genSortString(17, MAX_ALPHA2),
				genRand(8, MAX_ALPHA2));
		print(genSortString2(MAX_LENGTH1, MAX_ALPHA2),
				genRand(MAX_LENGTH1, MAX_ALPHA2));
		print(genRand(MAX_LENGTH1, MAX_ALPHA2),
				genRand(MAX_LENGTH1, MAX_ALPHA2));

		// Other test (length <= 100000, alpha = 2)
		emptyAns(MAX_LENGTH2, MAX_LENGTH2, MAX_ALPHA2);
		print(genRand(MAX_LENGTH2, MAX_ALPHA2),
				genRand(MAX_LENGTH2, MAX_ALPHA2));
		print(genRand(MAX_LENGTH2, MAX_ALPHA2), genFill(MAX_LENGTH2, 'z'));
		print(genSortString(MAX_LENGTH2, MAX_ALPHA2),
				genSortString2(MAX_LENGTH2, MAX_ALPHA2));
		print(genSpecialString(MAX_LENGTH2, MAX_ALPHA2),
				genRand(MAX_LENGTH2, MAX_ALPHA2));

		print(genSpecialString(MAX_LENGTH2, MAX_ALPHA2),
				genSortString(MAX_LENGTH2, MAX_ALPHA2));
		print(genFill(MAX_LENGTH2, 'z'), genFill(MAX_LENGTH2, 'z'));
		print(genSortString(MAX_LENGTH2, MAX_ALPHA2),
				genRand(MAX_LENGTH2, MAX_ALPHA2));
		print(genSortString2(MAX_LENGTH2, MAX_ALPHA2),
				genRand(MAX_LENGTH2, MAX_ALPHA2));
		print(genRand(MAX_LENGTH2, MAX_ALPHA2),
				genRand(MAX_LENGTH2, MAX_ALPHA2));
                                                                                
        
        print(genRand(randLength(MAX_LENGTH2 - 1), MAX_ALPHA2 - 1) + "z",
				genRand(randLength(MAX_LENGTH2), MAX_ALPHA2));
		print(genRand(randLength(MAX_LENGTH2), MAX_ALPHA2),
				genRand(randLength(MAX_LENGTH2), MAX_ALPHA2));
		print(genRand(randLength(MAX_LENGTH2), MAX_ALPHA2),
				genFill(randLength(MAX_LENGTH2), 'z'));
		print(genSortString(randLength(MAX_LENGTH2), MAX_ALPHA2),
				genSortString2(randLength(MAX_LENGTH2), MAX_ALPHA2));
		print(genSpecialString(randLength(MAX_LENGTH2), MAX_ALPHA2),
				genRand(randLength(MAX_LENGTH2), MAX_ALPHA2));

		print(genSpecialString(randLength(MAX_LENGTH2), MAX_ALPHA2),
				genSortString(randLength(MAX_LENGTH2), MAX_ALPHA2));
		print(genFill(randLength(MAX_LENGTH2), 'z'),
				genFill(randLength(MAX_LENGTH2), 'z'));
		print(genSortString(randLength(MAX_LENGTH2), MAX_ALPHA2),
				genRand(randLength(MAX_LENGTH2), MAX_ALPHA2));
		print(genSortString2(randLength(MAX_LENGTH2), MAX_ALPHA2),
				genRand(randLength(MAX_LENGTH2), MAX_ALPHA2));
		print(genRand(randLength(MAX_LENGTH2), MAX_ALPHA2),
				genRand(randLength(MAX_LENGTH2), MAX_ALPHA2));
		return;
	}
}
