#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
	char da[102][102];
	int d,n,i,j,x,y,c,f=0,dx,dy,dm;
	cin >> d; 
	for (;d>0;d--) {
		cin >> n;
		for (i=0;i<n+1;i++) for (j=0;j<n+1;j++) da[i][j]=' ';
		for (i=0;i<n+2;i++) {da[i][n+1]='#'; da[n+1][i]='#';}
		dx=0; dy=-1; x=0; y=n-1; c=0;
		while(true) {
			da[y][x]='#';
			if (da[y+dy*2][x+dx*2]=='#' || y+dy==-1) {
				c++; dm=dx; dx=-dy; dy=dm;
				if (c==n) break;
			}
			x+=dx; y+=dy;
		}
		if (f==1) cout << endl; else f=1; 
		for (i=0;i<n;i++) {
			for (j=0;j<n;j++) cout << da[i][j];
			cout << endl;
		}
	}
	return 0;
}