#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

int sp[101][101];

int main(){
	int e;
	cin>>e;
	int flag=0;
	while(e--){
		if(flag)puts("");
		++flag;
		int n;
		cin>>n;
		if(n==1){
			cout<<"#"<<endl;
			continue;
		}
		memset(sp,0,sizeof(sp));
		
		int y=n-1,x=0,d=0;
		int c=0;
		while(true){
			
			
			if(d==0){
				if(sp[y-1][x+1]==1)break;
				int cy=y;
				while(cy>=1){
					if(cy>=2 && sp[cy-2][x]==1)break;
					--cy;
				}
				if(y==cy)break;
				d=(d+1)%4;
				for(;cy<=y;y--)sp[y][x]=1;
				++y;
				continue;
			}
			
			if(d==1){
				if(sp[y+1][x+1]==1)break;
				int cx=x;
				while(cx<=n-2){
					if(cx<=n-3 && sp[y][cx+2]==1)break;
					++cx;
				}
				if(x==cx)break;
				d=(d+1)%4;
				for(;cx>=x;x++)sp[y][x]=1;
				--x;
				continue;
			}
			
			if(d==2){
				if(sp[y+1][x-1]==1)break;
				int cy=y;;
				while(cy<=n-2 && !(cy<=n-3 && sp[cy+2][x]==1))++cy;
				if(cy==y)break;
				d=(d+1)%4;
				for(;cy>=y;y++)sp[y][x]=1;
				--y;
				continue;
			}
			
			if(d==3){
				if(sp[y-1][x-1]==1)break;
				int cx=x;
				while(cx>=1 && !(cx>=2 && sp[y][cx-2]==1))--cx;
				if(x==cx)break;
				d=(d+1)%4;
				for(;cx<=x;x--)sp[y][x]=1;
				++x;
				continue;
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(sp[i][j])printf("#");
				else printf(" ");
			}
			puts("");
		}

	}
}