#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
int main() {
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		if (b)cout << endl;
		int c;
		cin >> c;
		bool d[100][100]{};
		int x = c - 1, y = 0;
		for (int i = 0;i<10000; i++) {
			while (1) {
				d[x][y] = true;
				if (x + dx[i%4] < 0 || x + dx[i%4] >= c || y + dy[i%4] < 0 || y + dy[i%4] >= c)break;
				int sum = 0;
				for (int p = 0; p < 4; p++) {
					if (x + dx[i % 4] + dx[p] >= 0 && x + dx[i % 4] + dx[p] < c && y + dy[i % 4] + dy[p] >= 0 && y + dy[i % 4] + dy[p] < c&&d[x + dx[i % 4] + dx[p]][y + dy[i % 4] + dy[p]]) {
						sum++;
					}
				}
				if (sum > 1)break;
				x += dx[i % 4]; y += dy[i % 4];
			}
		}
		for (int k = 0; k < c; k++) {
			for (int l = 0; l < c; l++) {
				if (d[k][l])cout << "#";
				else cout << " ";
			}
			cout << endl;
		}
	}
}