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

public class Tests {
    public static void main(String[] args) throws IOException {
        new Tests().run();
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    int tNumber, tNumberPre;
    int subtask;
    Random rnd;
    final int MAXLEN = 200000;
    final int MAXLENSUBTASK2 = 50;
    final int MAXLENSUBTASK3 = 1000;

    void printPre(String s) throws IOException {
        System.err.println("Preliminary...");
        if (tNumberPre < 10) {
            out = new PrintWriter("../preliminary/0" + tNumber);
        } else {
            out = new PrintWriter("../preliminary/" + tNumber);
        }
        tNumberPre++;

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

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


    ArrayList<String> tests;
    void genTestsDesc() throws FileNotFoundException {
        out = new PrintWriter("../tests.desc");
        for (String s : tests) {
            out.println(s);
        }
        out.close();
    }

    void printa(int n, char ch) throws IOException {
        char[] c = new char[n];
        for (int i = 0; i < n; i++) {
            c[i] = ch;
        }
        print(new String(c));
    }
    void genSimple() throws IOException {
        tests.add("../preliminary/01    Sample test 'abba'");
        printPre("abba");
    }

    void genSubtask1() throws IOException {
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " Test contains 50 letters 'a'");
        printa(50, 'a');
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " Test contains 50 letters 'b'");
        printa(50, 'b');

        StringBuilder test = new StringBuilder();
        for (int i = 0; i < 25; i++) {
            test.append("ab");
        }
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " Test contains 25 concatenated strings 'ab'");
        print(new String(test));

        test = new StringBuilder();
        for (int i = 5; i >= 0; i--) {
            int j = 6 - i;
            for (int t = 0; t < i; t++) {
                test.append("a");
            }
            for (int t = 0; t < j; t++) {
                test.append("b");
            }
        }
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " Easy stairs from left up to right down with len = " + test.length());
        print(new String(test));

        test = new StringBuilder();
        for (int i = 5; i >= 0; i--) {
            int j = 6 - i;
            for (int t = 0; t < j; t++) {
                test.append("a");
            }
            for (int t = 0; t < i; t++) {
                test.append("b");
            }
        }
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " Easy stairs from left down to right up with len = " + test.length());
        print(new String(test));

        test = new StringBuilder();
        int[] hand = {3, 5, 1, 4, 2};
        for (int i : hand) {
            int j = 6 - i;
            for (int t = 0; t < j; t++) {
                test.append("a");
            }
            for (int t = 0; t < i; t++) {
                test.append("b");
            }
        }
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " Permutation of length with len = " + test.length());
        print(new String(test));

        randomTwoLetters(50, 10);
        randomTwoLetters(50, 7);
        randomTwoLetters(50, 13);
        halfabNoise(50, 0);
    }

    void randomTwoLetters(int n, int max) throws  IOException {
        ArrayList<Integer> perm = new ArrayList<Integer>();
        int sum = n;
        while (sum > 0) {
            int x = rnd.nextInt(Math.min(max, sum)) + 1;
            perm.add(x);
            sum -= x;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < perm.size(); i++) {
            for (int j = 0; j < perm.get(i); j++) {
                sb.append((char)('a' + (i % 2)));
            }
        }
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " Random sequence of a and b with len = " + n);
        print(new String(sb));
    }

    void genSubtask2() throws IOException {
        randomLetters(MAXLENSUBTASK2, 3);
        randomLetters(MAXLENSUBTASK2, 3);
        randomLetters(MAXLENSUBTASK2, 3);
        randomLetters(MAXLENSUBTASK2, 5, "abc");
        randomLetters(MAXLENSUBTASK2, 5, "xyz");
        randomLetters(MAXLENSUBTASK2, 5, "agz");
        randomLetters(MAXLENSUBTASK2, 5, "zga");
        randomLetters(MAXLENSUBTASK2, 3, "abc");
        randomLetters(MAXLENSUBTASK2, 3, "xyz");
        randomLetters(MAXLENSUBTASK2, 3, "agz");
        randomLetters(MAXLENSUBTASK2, 3, "zga");
        randomLetters(MAXLENSUBTASK2, 3, "akrbc");
        randomLetters(MAXLENSUBTASK2, 3, "xyhez");
        randomLetters(MAXLENSUBTASK2, 3, "agdlz");
        randomLetters(MAXLENSUBTASK2, 3, "zlmrvga");
        halfabNoise(MAXLENSUBTASK2, 0);
        halfabNoise(MAXLENSUBTASK2, 2);
        halfabNoise(MAXLENSUBTASK2, -3);
        halfabLeftRightNoise(MAXLENSUBTASK2);
    }
    void genSubtask3() throws IOException {
        randomLetters(MAXLENSUBTASK3, 10);
        randomLetters(MAXLENSUBTASK3, 5);
        randomLetters(MAXLENSUBTASK3, 5);
        randomLetters(MAXLENSUBTASK3, 5);
        randomLetters(MAXLENSUBTASK3, 5);
        randomLetters(MAXLENSUBTASK3, 5);
        halfabNoise(MAXLENSUBTASK3,0);
        halfabNoise(MAXLENSUBTASK3,100);
        halfabNoise(MAXLENSUBTASK3,7);
        halfabNoise(MAXLENSUBTASK3,-8);

        halfabLeftRightNoise(MAXLENSUBTASK3);
        genAll(MAXLENSUBTASK3, 5);
        genAll(MAXLENSUBTASK3, 10);
        genAll(MAXLENSUBTASK3, 10);
        genAll(MAXLENSUBTASK3, 10);
    }

    void genSubtask4() throws IOException {
        randomLetters(MAXLEN, 10);
        randomLetters(MAXLEN, 15);
        randomLetters(MAXLEN, 100);
        randomLetters(MAXLEN, 5);
        halfabNoise(MAXLEN, 0);
        halfabNoise(MAXLEN, 10);
        halfabNoise(MAXLEN, -13);
        halfabLeftRightNoise(MAXLEN);
        genAllByLen(1);
        genAll(MAXLEN, 10);
        genAll(MAXLEN, 100);
        genAll(MAXLEN, 1000);
        genAll(MAXLEN, 1000);
        genAll(MAXLEN, 1000);
    }

    void randomLetters(int n, int max) throws  IOException {
        ArrayList<Integer> perm = new ArrayList<Integer>();
        int sum = n;
        while (sum > 0) {
            int x = rnd.nextInt(Math.min(max, sum)) + 1;
            perm.add(x);
            sum -= x;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < perm.size(); i++) {
            int y = rnd.nextInt(26);
            for (int j = 0; j < perm.get(i); j++) {
                sb.append((char)('a' + y));
            }
        }
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " Random sequence of all letters with len = " + n);
        print(new String(sb));
    }

    void randomLetters(int n, int max, String alph) throws  IOException {
        ArrayList<Integer> perm = new ArrayList<Integer>();
        int sum = n;
        while (sum > 0) {
            int x = rnd.nextInt(Math.min(max, sum)) + 1;
            perm.add(x);
            sum -= x;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < perm.size(); i++) {
            int y = rnd.nextInt(alph.length());
            for (int j = 0; j < perm.get(i); j++) {
                sb.append(alph.charAt(y));
            }
        }
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " Random sequence of letters from string \"" + alph + "\" with len = " + n);
        print(new String(sb));
    }


    void halfabNoise(int n, int noise) throws IOException{
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n / 2 - noise; i++) {
            sb.append('a');
        }
        for (int i = n / 2 - noise; i < n; i++) {
            sb.append('b');
        }
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " a repeats about n/2 times, then b repeats about n/2 times, len = " + n);
        print(new String(sb));
    }


    void halfabLeftRightNoise(int n) throws IOException{
        StringBuilder sb = new StringBuilder();
        sb.append("z");
        n -= 2;
        for (int i = 0; i < n / 2; i++) {
            sb.append('a');
        }
        for (int i = n / 2; i < n; i++) {
            sb.append('b');
        }
        n += 2;
        sb.append("k");
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " one symbol at the start and at the end, in middle a repeats n/2 times, then b repeats n/2 times, len = " + n);
        print(new String(sb));
    }


    void genAllByLen(int maxlen)throws IOException{
        StringBuilder sb = new StringBuilder();
        for (int i = 'a'; i <= 'z'; i++) {
            for (int j = i + 1; j <= 'z'; j++) {
                sb.append((char)i);
                sb.append((char)j);
            }
        }
        StringBuilder test = new StringBuilder();
        char[] c = (new String(sb)).toCharArray();
        for (int i = 0; i < c.length; i++) {
            int x = rnd.nextInt(maxlen) + 1;
            for (int j = 0; j < x;j++) {
                test.append(c[i]);
            }
        }
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " all combinations len = " + test.length());
        print(new String(test));
    }

    void genAll(int n, int maxlen)throws IOException{
        StringBuilder sb = new StringBuilder();
        for (int i = 'a'; i <= 'z'; i++) {
            for (int j = i + 1; j <= 'z'; j++) {
                sb.append((char)i);
                sb.append((char)j);
            }
        }
        StringBuilder test = new StringBuilder();
        char[] c = (new String(sb)).toCharArray();
        int i = 0;
        while (test.length() < n) {
            int x = rnd.nextInt(Math.min(maxlen, n - test.length())) + 1;
            for (int j = 0; j < x; j++) {
                test.append(c[i % c.length]);
            }
            i++;
        }
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " all combinations len = " + test.length());
        print(new String(test));
    }

    public void generate() throws IOException {
        new File("../tests").mkdir();
        new File("../tests/subtask1").mkdir();
        new File("../tests/subtask2").mkdir();
        new File("../tests/subtask3").mkdir();
        new File("../tests/subtask4").mkdir();
        new File("../preliminary").mkdir();

        tNumber = 1;
        tNumberPre = 1;
        tests = new ArrayList<String>();
        genSimple();
        rnd = new Random(313131311);

        subtask = 1;
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " Just ab");
        print("ab");
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " Just a");
        print("a");
        tests.add("../tests/subtask" + subtask + "/" + (tNumber / 10) + (tNumber % 10) + " Just b");
        print("b");
        genSubtask1();

        subtask = 2;

        genSubtask2();

        subtask = 3;
        genSubtask3();


        subtask = 4;
        genSubtask4();

        genTestsDesc();
    }

    public void run() throws IOException {
        //Locale.setDefault(Locale.US);
        generate();
    }
}