#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int n;
char s[105][105];
int dx[]{ -1,0,1,0 }, dy[]{ 0,1,0,-1 };

void dfs(int idx, int x, int y) {
	if (s[x][y] == '#')return;
	s[x][y] = '#';
	int nx = x + dx[idx], ny = y + dy[idx];
	if (nx < 0 || n <= nx || ny < 0 || n <= ny) {
		idx = (idx + 1) % 4;
		dfs(idx, x + dx[idx], y + dy[idx]);
		return;
	}
	int kx = nx + dx[idx], ky = ny + dy[idx];
	if (!(0 <= kx&&kx < n && 0 <= ky&&ky < n&&s[kx][ky] == '#')) {
		dfs(idx, nx, ny);
		return;
	}
	idx = (idx + 1) % 4;
	nx = x + dx[idx], ny = y + dy[idx];
	kx = nx + dx[idx], ky = ny + dy[idx];
	int jx = nx + dx[(idx + 1) % 4], jy = ny + dy[(idx + 1) % 4];
	if ((!(0 <= kx&&kx < n && 0 <= ky&&ky < n&&s[kx][ky] == '#'))&& (!(0 <= jx&&jx < n && 0 <= jy&&jy < n&&s[jx][jy] == '#'))) {
		dfs(idx, nx, ny);
		return;
	}
}
int main() {
	int d; scanf("%d", &d);
	rep(i, d) {
		scanf("%d", &n);
		if (n == 1) {
			puts("#"); continue;
		}
		rep(j, n)rep(k, n)s[j][k] = ' ';
		dfs(0, n - 1, 0);
		rep(j, n)printf("%s\n", s[j]);
	}
}