import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;

public class TestsGen {

	final static Random rand = new Random(1234567L);
	final static int ALPHABET = 10;
	final static int MAXLEN = 1000000;
	final static int THRESHOLD_HIGH = 10000;
	final static int THRESHOLD_LOW2 = 3000;
	final static int THRESHOLD_LOW1 = 500;

	public static void main(String[] args) {
		testsNum = 0;
		printManyAverageStrings(rand.nextInt(5) + 1, THRESHOLD_LOW1,
				rand.nextInt(3) + 1);
		printManyAverageStrings(random(1, THRESHOLD_LOW1),
				random(1, THRESHOLD_LOW1), rand.nextInt(ALPHABET) + 1);
		printManyAverageStrings(random(1, THRESHOLD_LOW1),
				random(1, THRESHOLD_LOW1), rand.nextInt(ALPHABET) + 1);
		printManySmallStrings(random(1, THRESHOLD_LOW1),
				random(1, THRESHOLD_LOW1), rand.nextInt(ALPHABET) + 1);
		printManySmallStrings(random(1, THRESHOLD_LOW1),
				random(1, THRESHOLD_LOW1), rand.nextInt(ALPHABET) + 1);
		printManySmallStrings(THRESHOLD_LOW1, THRESHOLD_LOW1, 1);
		printSpecialOneLetterStrings(THRESHOLD_LOW1, ALPHABET);
		printPeriodManyAverageStrings(THRESHOLD_LOW1 / 10, 10, THRESHOLD_LOW1,
				3);

		printSpecialOneLetterStrings(MAXLEN, ALPHABET);
		printManyAverageStrings(MAXLEN, MAXLEN, 1);
		printManySmallStrings(MAXLEN, MAXLEN, 1);
		printOneString(MAXLEN, MAXLEN, 1);
		printPeriodManyAverageStrings(THRESHOLD_HIGH, 10, MAXLEN, 3);
		printPeriodLargeStrings(THRESHOLD_HIGH, 10, MAXLEN, 1);
		printManyAverageStrings(random(THRESHOLD_HIGH, MAXLEN),
				random(THRESHOLD_HIGH, MAXLEN), rand.nextInt(ALPHABET) + 1);
		printManySmallStrings(random(THRESHOLD_HIGH, MAXLEN),
				random(THRESHOLD_HIGH, MAXLEN), rand.nextInt(ALPHABET) + 1);
		printOneString(random(THRESHOLD_HIGH, MAXLEN),
				random(THRESHOLD_HIGH, MAXLEN), rand.nextInt(ALPHABET) + 1);
		printManyAverageStrings(random(THRESHOLD_HIGH, MAXLEN),
				random(THRESHOLD_HIGH, MAXLEN), rand.nextInt(ALPHABET) + 1);
		printManyAverageStrings(random(THRESHOLD_HIGH, MAXLEN),
				random(THRESHOLD_HIGH, MAXLEN), rand.nextInt(ALPHABET) + 1);
		printManySmallStrings(random(THRESHOLD_HIGH, MAXLEN),
				random(THRESHOLD_HIGH, MAXLEN), rand.nextInt(ALPHABET) + 1);
	}

	static void printSpecialOneLetterStrings(int n, int k) {
		String t = getRandomString(n, 1);
		ArrayList<String> s = new ArrayList<String>();
		s.add(getRandomString(n / 3, k));
		n -= n / 3;
		while (n > 0) {
			s.add(getRandomString(1, k));
			n--;
		}
		Test.print(t, s);
	}

	static int random(int i, int j) {
		return rand.nextInt(j - i + 1) + i;
	}

	static void printPeriodLargeStrings(int n, int n2, int m, int k) {
		int e = m / 8;
		String t = getPeriodString(n, n2, k);
		ArrayList<String> s = new ArrayList<String>();
		while (m > 0) {
			int len = rand.nextInt(Math.min(m, e)) + 1;
			s.add((rand.nextInt() & 4) == 0 ? getRandomString(len, ALPHABET)
					: getRandomString(len, k));
			m -= len;
		}
		Test.print(t, s);
	}

	static void printPeriodManyAverageStrings(int n, int n2, int m, int k) {
		int e = (int) Math.sqrt(m) * 2;
		String t = getPeriodString(n, n2, k);
		ArrayList<String> s = new ArrayList<String>();
		s.add(getRandomString(m / 3, k));
		m -= m / 3;
		while (m > 0) {
			int len = rand.nextInt(Math.min(m, e)) + 1;
			s.add((rand.nextInt() & 4) == 0 ? getRandomString(len, ALPHABET)
					: getRandomString(len, k));
			m -= len;
		}
		Test.print(t, s);
	}

	static void printManyAverageStrings(int n, int m, int k) {
		int e = (int) Math.sqrt(m) * 2;
		String t = getRandomString(n, k);
		ArrayList<String> s = new ArrayList<String>();
		s.add(getRandomString(m / 3, k));
		m -= m / 3;
		while (m > 0) {
			int len = rand.nextInt(Math.min(m, e)) + 1;
			s.add((rand.nextInt() & 4) == 0 ? getRandomString(len, ALPHABET)
					: getRandomString(len, k));
			m -= len;
		}
		Test.print(t, s);
	}

	static void printManySmallStrings(int n, int m, int k) {
		int e = 5;
		String t = getRandomString(n, k);
		ArrayList<String> s = new ArrayList<String>();
		s.add(getRandomString(m / 3, k));
		m -= m / 3;
		while (m > 0) {
			int len = rand.nextInt(Math.min(m, e)) + 1;
			s.add((rand.nextInt() & 4) == 0 ? getRandomString(len, ALPHABET)
					: getRandomString(len, k));
			m -= len;
		}
		Test.print(t, s);
	}

	static void printOneString(int n, int m, int k) {
		String s = getRandomString(n, k);
		String[] t = new String[] { getRandomString(m, k) };
		Test.print(s, t);
	}

	static String getPeriodString(int n, int m, int k) {
		String s = getRandomString(m, k);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			sb.append(s);
		}
		return sb.toString();
	}

	static String getRandomString(int n, int k) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			sb.appendCodePoint(rand.nextInt(k) + 'a');
		}
		return sb.toString();
	}

	static int testsNum;

	static class Test {

		static void print(String t, Collection<String> s) {
			print(t, s.toArray(new String[s.size()]));
		}

		static void print(String t, String[] s) {
			++testsNum;
			System.err.println("Generating test #" + testsNum);
			PrintWriter out = null;
			try {
				out = new PrintWriter(testsNum / 10 + "" + testsNum % 10);
				out.println(t);
				out.println(s.length);
				for (String e : s) {
					out.println(e);
				}
			} catch (IOException e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			} finally {
				if (out != null) {
					out.close();
				}
			}
		}
	}
}
