#ifdef DEBUG
#  define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include "testlib.h"
#define ff first
#define ss second
#define szof(x) ((int)x.size())
#ifndef LOCAL
#  define cerr __get_ce
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;

void MakeNonZero(vector<string>& s) {
  int n = (int) s.size();
  for (int rot = 0; rot < 2; rot++) {
    for (int i = 0; i < n; i++) {
      int beg = 0;
      while (beg < n) {
        if (s[i][beg] != '?') {
          beg += 1;
          continue;
        }
        int end = beg;
        while (end + 1 < n && s[i][end + 1] == '?') {
          end += 1;
        }
        int blacks = 0;
        blacks += (beg > 0 && s[i][beg - 1] == '#');
        blacks += (end < n - 1 && s[i][end + 1] == '#');
        if (blacks == 2) {
          if (rnd.next(0, 1) == 0) {
            s[i][beg - 1] = '.';
          } else {
            s[i][end + 1] = '.';
          }
        }
        beg = end + 1;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        swap(s[i][j], s[j][i]);
      }
    }
  }
}

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

	int n;
	if (has_opt("minn")) {
		int minn = opt<int>("minn");
		int maxn = opt<int>("maxn");
		n = rnd.next(minn, maxn);
	} else {
		n = opt<int>("n");
	}


	vector<string> s(n, string(n, ' '));
	double p1 = (has_opt("p1") ? opt<double>("p1") : 1.0 / 3);
	double p2 = (has_opt("p2") ? opt<double>("p2") : 1.0 / 3);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			double x = rnd.next();
			char c;
			if (x < p1) {
				c = '.';
			} else {
				if (x < p1 + p2) {
					c = '#';
				} else {
					c = '?';
				}
			}
			s[i][j] = c;
		}
	}

	MakeNonZero(s);

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

	return 0;
}