#include <iostream>
#include <vector>

using namespace std;

int main(void){
  int d;cin>>d;
  const int POS[][2]={{0,-1},{1,0},{0,1},{-1,0}};
  while(d--){
    int n;cin>>n;
    vector<vector<char> > field(n+2);
    for(int i=0;i<=n+1;++i){
      field[i].reserve(n+2);
      for(int j=0;j<=n+1;++j)field[i][j]=(i==n+1||j==n+1)?1:0;
    }
    int x=0,y=n-1,p=0;
    for(;;){
    	if(x<0||y<0)break;
      int dx=POS[p][0],dy=POS[p][1];
      int px=POS[(p+4+1)%4][0],py=POS[(p+4+1)%4][1],qx=POS[(p+4-1)%4][0],qy=POS[(p+4-1)%4][1];
      field[y][x]=1;
      x+=dx,y+=dy;
      if(y==0&&x==0||(y+2*dy>=0&&x+2*dx>=0&&field[y+2*dy][x+2*dx]==1))p=(p+1)%4;
      if((y+dy+py>=0&&x+dx+px>=0&&field[y+dy+py][x+dx+px]==1)||(y+dy+qy>=0&&x+dx+qx>=0&&field[y+dy+qy][x+dx+qx]==1))
      	break;
    }
    if(n==2)field[1][1]=0;
    for(int i=0;i<n;++i){
      for(int j=0;j<n;++j)cout<<((field[i][j])?'#':' ');
      cout<<endl;
    }
    if(d)cout<<endl;
  }
  return 0;
}