#include <bits/stdc++.h>
using namespace std;
void put(vector<string> & g, int i, int j, int sh, int n = 0) {
g[sh + i][sh + j] = '#';
if (n) {
put(g, n - 1 - j, i, sh, 0);
}
}
void sol(vector<string> & g, int n, int sh) {
if (n < 2) {
return;
}
if (n == 3) {
put(g, 0, 0, sh);
put(g, 1, 0, sh);
put(g, 0, 2, sh);
put(g, 1, 2, sh);
} else if (n % 3 == 2) {
if (n % 2 == 0) {
for (int i = 0; i < n; i += 3) {
for (int j = 0; j < n - 3; j += 2) {
put(g, j, i, sh);
put(g, j, i + 1, sh);
}
}
for (int i = 0; i < n; i += 2) {
put(g, n - 1, i, sh);
put(g, n - 2, i, sh);
}
} else {
for (int i = 0; i < n; i += 3) {
for (int j = 0; j < n; j += 2) {
put(g, j, i, sh);
put(g, j, i + 1, sh);
}
}
}
} else if (n % 3 == 1) {
for (int i = 0; i < n - 3; i += 3) {
put(g, i, 0, sh, n);
put(g, i + 1, 0, sh, n);
put(g, n - 1 - (i), n - 1, sh, n);
put(g, n - 1 - (i + 1), n - 1, sh, n);
}
sol(g, n - 4, sh + 2);
} else {
for (int i = 0; i < n - 3; i += 3) {
put(g, i, 0, sh, n);
put(g, i + 1, 0, sh, n);
put(g, i, 2, sh, n);
put(g, i + 1, 2, sh, n);
put(g, n - 1 - (i), n - 1, sh, n);
put(g, n - 1 - (i + 1), n - 1, sh, n);
put(g, n - 1 - (i), n - 3, sh, n);
put(g, n - 1 - (i + 1), n - 3, sh, n);
}
sol(g, n - 8, sh + 4);
}
}
void solve() {
int n;
cin >> n;
vector<string> g(n, string(n, '.'));
sol(g, n, 0);
for (const string & s : g) {
cout << s << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
}