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

public class Tests {
	Random rnd = new Random(239);
	int tests = 1;
	int MAXN = 100;
	int MAXT = 6;
	int MAXK = 8;

	int[] dx = { 1, 0, -1, 0 };
	int[] dy = { 0, 1, 0, -1 };

	public void writeTest(int t, boolean[][] a) {
		try {
			PrintWriter out = new PrintWriter(String.format("../tests/%02d",
					tests++));

			out.println(a.length + " " + a[0].length + " " + t);
			for (int i = 0; i < a.length; i++) {
				for (int j = 0; j < a[i].length; j++) {
					out.print(a[i][j] ? '*' : '.');
				}
				out.println();
			}
			out.println();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public int nextInt(int pow) {
		return rnd.nextInt() & ((1 << pow) - 1);
	}

	public void fill(boolean[][] a, int x, int y, int d, boolean intersect) {
		if (intersect)
			return;
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a.length; j++) {
				if (Math.abs(x - i) + Math.abs(y - j) <= d)
					a[i][j] = true;
			}
		}
	}

	public void genLogic(int n, int m, int t, int k, int d, boolean intersect,
			boolean[][] b) {
		k = Math.min(k, n * m - 1);
		d = Math.min(d, k);
		t = Math.min(t, n * m - k);

		boolean[][] a = new boolean[n][m];

		int[] x = new int[k];
		int[] y = new int[k];

		for (int i = 0; i < d; i++) {
			x[i] = rnd.nextInt(n);
			y[i] = rnd.nextInt(m);

			int it = 0;

			while (b[x[i]][y[i]] && it < 10000) {
				x[i] = rnd.nextInt(n);
				y[i] = rnd.nextInt(m);
				it++;
			}

			fill(b, x[i], y[i], t, intersect);

			a[x[i]][y[i]] = true;
		}

		for (int i = d; i < k; i++) {
			int ind = rnd.nextInt(i);

			boolean good = false;
			for (int it = 0; !good || it < 10; it++) {
				int dir = rnd.nextInt(4);
				int tx = x[ind] + dx[dir];
				int ty = y[ind] + dy[dir];
				if (tx < 0 || tx >= n || ty < 0 || ty >= m)
					continue;
				good = true;
				x[i] = tx;
				y[i] = ty;
			}

			a[x[i]][y[i]] = true;
		}
		writeTest(t, a);
	}

	public void genLogic(int n, int m, int t, int k, int d, boolean intersect) {
		genLogic(n, m, t, k, d, intersect, new boolean[n][m]);
	}

	public void genLogicBorders(int n, int m, int t, int k, int d,
			boolean intersect) {
		boolean[][] b = new boolean[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (i <= d || j <= d || Math.abs(n - i) <= d
						|| Math.abs(m - j) <= d)
					b[i][j] = true;
			}
		}

		genLogic(n, m, t, k, d, intersect, b);
	}

	public void gen() {
		if (!new File("../tests").exists()) {
			new File("../tests").mkdir();
		}

		writeTest(1, new boolean[][] { { true, false }, { false, false } });
		writeTest(2, new boolean[][] { { true, false }, { false, false } });
		writeTest(3, new boolean[][] { { true, false }, { false, false } });

		genLogic(2, 2, MAXT, 4, 1, true);
		for (int i = 0; i < 3; i++) {
			int k = rnd.nextInt(MAXK) + 1;
			genLogic(rnd.nextInt(10) + 1, rnd.nextInt(10) + 1,
					rnd.nextInt(MAXT) + 1, k, rnd.nextInt(k) + 1, true);
		}
		for (int i = 0; i < 20; i++) {
			int k = rnd.nextInt(MAXK) + 1;
			genLogic(rnd.nextInt(MAXN) + 1, rnd.nextInt(MAXN) + 1,
					rnd.nextInt(MAXT) + 1, k, rnd.nextInt(k) + 1, true);
		}

		boolean[][] a = new boolean[30][30];
		int xx = rnd.nextInt(a.length - 3);
		int yy = rnd.nextInt(a[0].length - 3);
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				a[xx + i][yy + j] = true;
			}
		}

		a[xx + 1][yy + 1] = false;

		writeTest(6, a);

		genLogic(1, MAXN, MAXT, MAXK, rnd.nextInt(MAXK) + 1, true);
		genLogic(MAXN, 1, MAXT, MAXK, rnd.nextInt(MAXK) + 1, true);

		for (int i = 1; i <= MAXK; i++) {
			genLogic(MAXN, MAXN, MAXT, MAXK, i, false);
			genLogic(MAXN, MAXN, MAXT, MAXK, i, true);
			genLogicBorders(MAXN, MAXN, MAXT, MAXK, i, false);
		}
	}

	public static void main(String[] args) {
		new Tests().gen();
	}
}
