#include "testlib.h"

using namespace std;

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

using Field = std::vector<std::string>;

bool check(const Field& f, int n, int m) {
	int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (f[i][j] == 's') x1 = i, y1 = j;
			if (f[i][j] == 'f') x2 = i, y2 = j;
		}
	}
	std::vector<std::vector<bool>> used(n, std::vector<bool>(m));

	auto dfs = [&f, &used, &n, &m](auto self, int x, int y) -> void {
		used[x][y] = true;

		for (int i = 0; i < 4; ++i) {
			int newX = x + dx[i];
			int newY = y + dy[i];

			if (newX < 0 || newY < 0 || newX >= n || newY >= m) {
				continue;
			}
			if (used[newX][newY] || f[newX][newY] == '#') {
				continue;
			}

			self(self, newX, newY);
		}
	};
	dfs(dfs, x1, y1);

	return used[x2][y2];
}

int main(int argc, char** argv) {
  registerGen(argc, argv, 1);

  int n = opt<int>("n");
  int m = opt<int>("m");
  int dir = opt<int>("dir");
  int mask = opt<int>("mask");
  int w = opt<int>("w");
  int rand_ends = opt<int>("rand_ends");
  int spoils = opt<int>("spoils");

  vector<string> s(n, string(m, '#'));
  pair<int, int> firs{-1, -1};
  pair<int, int> last{-1, -1};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (dir == 0) {
        if (i % (w + 1) == w) {
          int only = ((mask >> (i / 2 % 2)) & 1) * (m - 1);
          if (abs(j - only) > w - 1) {
            continue;
          }
        }
      } else {
        if (j % (w + 1) == w) {
          int only = ((mask >> (j / 2 % 2)) & 1) * (n - 1);
          if (abs(i - only) > w - 1) {
            continue;
          }
        }
      }
      s[i][j] = '.';
      if (firs.first == -1) {
        firs = make_pair(i, j);
      }
      last = make_pair(i, j);
    }
  }
  if (rand_ends) {
    for (char c : string("sf")) {
      int i, j;
      do {
        i = rnd.next(n);
        j = rnd.next(m);
      } while (s[i][j] != '.');
      s[i][j] = c;
    }
  } else {
    s[firs.first][firs.second] = 's';
    s[last.first][last.second] = 'f';
  }

  while (spoils--) {
    int i, j;
    while (true) {
      i = rnd.next(n);
      j = rnd.next(m);
      if (s[i][j] == 's' || s[i][j] == 'f') {
        continue;
      }
      s[i][j] = (s[i][j] == '.' ? '#' : '.');
      if (check(s, n, m)) {
        break;
      }
      s[i][j] = (s[i][j] == '.' ? '#' : '.');
    }
  }

  cout << 1 << '\n';
  cout << n << " " << m << '\n';
  for (int i = 0; i < n; i++) {
    cout << s[i] << '\n';
  }

  return 0;
}