/**
 * Created by GShark on 18.09.2014.
 */
import java.io.*;
import java.util.*;

public class TestGen {
    public static void main(String[] args) throws IOException {
        new TestGen().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;
    Random rnd;
    final int MAXN = 1000;
    ArrayList<String> test;

    int rand(int n) {
        return rnd.nextInt(n);
    }

    void print(ArrayList<String> al) throws IOException {
        System.err.println(tNumber);
        if (tNumber < 10) {
            out = new PrintWriter("../tests/0" + tNumber);
        } else {
            out = new PrintWriter("../tests/" + tNumber);
        }
        tNumber++;
        out.println(al.size() + " " + al.get(0).length());
        for (int i = 0; i < al.size(); i++)
            out.println(al.get(i));
        al.clear();
        out.close();
    }

    // here starts gens

    public void genSample() throws IOException {
        test.add(".OXOXO");
        test.add("OXX.O.");
        test.add("XXOOXX");
        test.add("..O..O");
        test.add("OOXX.X");
        print(test);
    }

    public void genSimple1() throws IOException {
        test.add("XX....");
        test.add(".XXXXX");
        print(test);
    }

    public void genSimple2() throws IOException {
        test.add("XX...O");
        test.add(".XXXXO");
        test.add(".....O");
        test.add(".....O");
        test.add(".....O");
        print(test);
    }

    public void genSimple3() throws IOException {
        test.add("XX....");
        test.add("OXX.XX");
        test.add(".O...O");
        test.add("..O...");
        test.add("...O..");
        test.add("...OO.");
        print(test);
    }

    public void genSimple4() throws IOException {
        test.add("XX...X");
        test.add(".X..XO");
        test.add("...XOO");
        test.add(".OX.OO");
        test.add(".X.OOO");
        print(test);
    }

    char randomLetter() {
        int k = rand(3);
        if (k == 0)
            return 'X';
        else if (k == 1)
            return 'O';
        else
            return '.';
    }

    String randomString(int len) {
        String ans = "";
        for (int i = 0; i < len; i++)
            ans += randomLetter();
        return ans;
    }

    public void genRandom(int maxn, int maxm) throws IOException {
        int n = rand(maxn / 2) + maxn / 2;
        int m = rand(maxm / 2) + maxm / 2;
        for (int i = 0; i < n; i++) {
            test.add(randomString(m));
        }
        print(test);
    }

    public void genRandomMax(int maxn, int maxm) throws IOException {
        int n = maxn;
        int m = maxm;
        for (int i = 0; i < n; i++) {
            test.add(randomString(m));
        }
        print(test);
    }

    public void genSpecial1(int n, int m) throws IOException {
        for (int i = 0; i < n; i++) {
            String cur = "";
            for (int j = 0; j < n; j++) {
                char c = '.';
                if (i % 8 < 4 && j % 8 < 4 || i % 8 >= 4 && j % 8 >= 4) {
                    c = 'X';
                } else {
                    c = 'O';
                }
                cur += c;
            }
            test.add(cur);
        }
        print(test);
    }

    public void genSpecial2(int n, int m) throws IOException {
        for (int i = 0; i < n; i++) {
            String cur = "";
            for (int j = 0; j < n; j++) {
                char c = '.';
                if (i % 8 < 4 && j % 8 < 4 || i % 8 >= 4 && j % 8 >= 4) {
                    c = 'X';
                } else {
                    c = 'O';
                }
                if (rand(4) == 2) {
                    c = '.';
                }
                cur += c;
            }
            test.add(cur);
        }
        print(test);
    }

    public void genSpecial3(int n, int m) throws IOException {
        for (int i = 0; i < n; i++) {
            String cur = "";
            for (int j = 0; j < n; j++) {
                char c = '.';
                if (i % 10 < 5 && j % 10 < 5 || i % 10 >= 5 && j % 10 >= 5) {
                    c = 'X';
                } else {
                    c = 'O';
                }
                cur += c;
            }
            test.add(cur);
        }
        print(test);
    }

    public void genSpecial5(int n, int m) throws IOException {
        for (int i = 0; i < n; i++) {
            String cur = "";
            for (int j = 0; j < n; j++) {
                char c = '.';
                if (i % 10 < 5 && j % 10 < 5 || i % 10 >= 5 && j % 10 >= 5) {
                    c = 'X';
                } else {
                    c = 'O';
                }
                if (i % 5 == 0 || j % 5 == 0) {
                    c = '.';
                }

                cur += c;
            }
            test.add(cur);
        }
        print(test);
    }

    public void genSpecial4(int n, int m) throws IOException {
        for (int i = 0; i < n; i++) {
            String cur = "";
            for (int j = 0; j < n; j++) {
                char c = '.';
                if (i % 10 < 5 && j % 10 < 5 || i % 10 >= 5 && j % 10 >= 5) {
                    c = 'X';
                } else {
                    c = 'O';
                }
                if (rand(4) == 2) {
                    c = '.';
                }
                cur += c;
            }
            test.add(cur);
        }
        print(test);
    }

    public void genSpecial6(int n, int m) throws IOException {
        for (int i = 0; i < n; i++) {
            String cur = "";
            for (int j = 0; j < m; j++) {
                cur += '.';
            }
            test.add(cur);
        }
        print(test);
    }

    public void genSpecial7(int n, int m) throws IOException {
        for (int i = 0; i < n; i++) {
            String cur = "";
            for (int j = 0; j < m; j++) {
                cur += 'O';
            }
            test.add(cur);
        }
        print(test);
    }



    //the end of the gens

    public void generate() throws IOException {
        new File("../tests").mkdir();
        tNumber = 1;
        rnd = new Random(388282447);
        test = new ArrayList<String>();
        genSample();
        genSimple1();
        genSimple2();
        genSimple3();
        genSimple4();
        genSpecial6(5, 5);
        genSpecial7(4, 4);
        genSpecial7(4, 6);
        genSpecial7(7, 3);
        for (int i = 10; i <= 50; i += 10) {
            genRandom(i, i);
        }
        genRandom(100, 3);
        genRandom(4, 150);
        for (int i = 100; i <= 1000; i += 100) {
            genRandom(i, i);
        }
        genRandomMax(1000, 1000);
        genSpecial1(1000, 1000);
        genSpecial2(1000, 1000);
        genSpecial3(1000, 1000);
        genSpecial4(1000, 1000);
        genSpecial5(1000, 1000);
        genSpecial6(1000, 1000);
        genSpecial7(1000, 1000);
    }

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