#include using namespace std; using int64 = long long; vector construct(int64 m) { constexpr int N = 40; vector s(N, string(N, '#')); // 中央の帯と、外側の2本の通路。 for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { const int d = abs(i - j); // 中央の帯は38×38で打ち切る。 if (i < 38 && j < 38 && d <= 2) { s[i][j] = '.'; } // 外側の階段状の通路。 if (4 <= d && d <= 5) { s[i][j] = '.'; } } } // 外側の通路をゴールにつなぐ。 for (int i = 34; i < N; ++i) { s[i][39] = '.'; s[39][i] = '.'; } // 3進法の下位36桁。 // 各kについて、重み3^kのスイッチ候補が2個ある。 for (int k = 0; k < 36; ++k) { const int digit = int(m % 3); m /= 3; if (digit >= 1) s[k][k + 3] = 'P'; if (digit >= 2) s[k + 3][k] = 'P'; } // ここでm = floor(元のM / 3^36) で、0 <= m <= 6。 // 末尾の4候補の重みは、それぞれ (2,2,1,1) * 3^36。 const tuple tail[] = { {37, 38, 2}, {38, 37, 2}, {36, 38, 1}, {38, 36, 1} }; for (auto [r, c, weight] : tail) { if (m >= weight) { s[r][c] = 'P'; m -= weight; } } assert(m == 0); return s; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; if (!(cin >> T)) return 0; while (T--) { int64 M; cin >> M; const auto s = construct(M); cout << s.size() << '\n'; for (const auto& row : s) { cout << row << '\n'; } } return 0; }