#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n,dy[]={-1,0,1,0},dx[]={0,1,0,-1};
char c[100][100];

int main(){
	cin>>n;
	int f=0;
	while(cin>>n){
		if(f)cout<<endl;
		if(n==1){cout<<"#"<<endl;f=1;continue;}
		for(int i=0;i<n*n;i++)c[i/n][i%n]=' ';
		int y=n-1,x=0,u=0,d=n-1,l=0,r=n-1;
		c[y][x]='#';
		for(int i=0;i<n;i++){
			while(1){
				y+=dy[i%4];x+=dx[i%4];
				c[y][x]='#';
				if(i%4==0&&y==u||i%4==1&&x==r||i%4==2&&y==d||i%4==3&&x==l)break;
			}
			if(i%4==0)l+=2;
			if(i%4==1)u+=2;
			if(i%4==2)r-=2;
			if(i%4==3)d-=2;
		}
		for(int i=0;i<n*n;i++){
			cout<<c[i/n][i%n];
			if(i%n==n-1)cout<<endl;
		}
		f=1;
	}
}