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

#define rep(i, n)for((i) = 0;(i) < (n);++(i))

char f[100][100];
int dh[4] = {-1, 0, 1, 0};
int dw[4] = {0, 1, 0, -1};
int main(void){
	int d, n, i, j;
	scanf("%d", &d);
	for(;d--;){
		scanf("%d", &n);
		rep(i, n)rep(j, n){
			f[i][j] = ' ';
			if(i == 0 || j == 0 || i == n - 1 || j == n - 1)f[i][j] = '#';
		}
		
		int w = 2, h = n - 1, k = 0;
		if(n != 2)f[h][w - 1] = ' ';
		if(n > 4)for(int times = 200000;times--;){
			//printf("%d %d\n", h, w);
			f[h][w] = '#';
			if(f[h + dh[k] + dh[k]][w + dw[k] + dw[k]] == '#')k = (k + 1) % 4;
			else if(f[h + dh[k] + dh[(k + 1) % 4]][w + dw[k] + dw[(k + 1) % 4]] == '#')k = (k + 1) % 4;
			else if(f[h + dh[k] + dh[(k + 3) % 4]][w + dw[k] + dw[(k + 3) % 4]] == '#')k = (k + 1) % 4;
			else{ h += dh[k]; w += dw[k]; }
		}

		rep(i, n){
			rep(j, n)printf("%c",f[i][j]);
			puts("");
		}
		if(d >= 0)puts("");
	}
	return 0;
}