#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int g=0,i,j,k;
  int x,y,n,nh,b[100][100];
  vector<int> h;
  cin>>n;
  h.reserve(n);
  for(i=0;i<n;i++)
    cin>>h[i];
  for(i=0;i<n;i++){
    memset(b,0,sizeof(b));
    for(j=0;j<h[i];j++)
      b[0][j]=1;
    nh=h[i];
    h[i]--;
    x=1;
    y=0;
    for(;;){
      if(h[i]<=0)
	break;
      for(j=0;j<h[i];j++)
	b[x+j][y]=1;
      x+=h[i]-1;
      y++;
      if(h[i]==1)
	break;
      for(j=0;j<h[i];j++)
	b[x][y+j]=1;
      x--;
      y+=h[i]-1;
      h[i]-=2;
      if(h[i]<=0)
	break;
      for(j=0;j<h[i];j++)
	b[x-j][y]=1;
      x-=h[i]-1;
      y--;
      if(h[i]==1)
	break;
      for(j=0;j<h[i];j++)
	b[x][y-j]=1;
      x++;
      y-=h[i]-1;
      h[i]-=2;
    }
    if(g)
      cout<<endl;
    g=1;
    for(j=0;j<nh;j++){
      for(k=0;k<nh;k++)
	if(b[k][j])
	  cout<<"#";
	else
	  cout<<" ";
      cout<<endl;
    }
  }
  return 0;
}