#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
using namespace std;
int d, n;
char m[110][110];
signed main() {
	cin >> d;
	for (int v = 0; v < d; v++) {
		if (v)cout << endl;
		cin >> n;
		for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)m[i][j] = ' ';
		int x = -1, y = 0, p = n - 1, q = 0;
		while (1) {
			m[p][q] = '#';
			if (p + x < 0) {
				if (n == 1)break;
				x = 0; y = 1;
			}
			if (q + y >= n) {
				if (n == 2)break;
				x = 1; y = 0;
			}
			if (p + x >= n) {
				if (n == 3)break;
				x = 0; y = -1;
			}
			if (y == -1 && m[p][q - 2] == '#') {
				if (m[p - 1][q + 1] == '#')break;
				x = -1; y = 0;
				if (m[p - 2][q] == '#')break;
			}
			if (x == -1 && m[p - 2][q] == '#') {
				if (m[p + 1][q + 1] == '#')break;
				x = 0; y = 1;
				if (m[p][q + 2] == '#')break;
			}
			if (y == 1 && m[p][q + 2] == '#') {
				if (m[p + 1][q - 1] == '#')break;
				x = 1; y = 0;
				if (m[p + 2][q] == '#')break;
			}
			if (x == 1 && m[p + 2][q] == '#') {
				if (m[p - 1][q - 1] == '#')break;
				x = 0; y = -1;
				if (m[p][q - 2] == '#')break;
			}
			p += x; q += y;
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++)cout << m[i][j];
			cout << endl;
		}
	}
}
