#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};

int main(void){
  int d;
  bool isfirst = true;
  cin >> d;

  for(int i=0;i<d;i++){
    int n;
    cin >> n;
    bool sharp[n][n];

    memset(sharp,false,sizeof(sharp));

    int x=n-1,y=0;
    int vec=0;
    int len = n-1;
    
    if(!isfirst) cout << endl;

    sharp[x][y] = true;
    while(len > 1){
      for(int j=0;j<len;j++){
	x += dx[vec];
	y += dy[vec];
	sharp[x][y] = true;
      }
      vec = (vec+1)%4;
      for(int j=0;j<len;j++){
	x += dx[vec];
	y += dy[vec];
	sharp[x][y] = true;
      }
      vec = (vec+1)%4;
      if(len == n-1){
	for(int j=0;j<len;j++){
	  x += dx[vec];
	  y += dy[vec];
	  sharp[x][y] = true;
	}
	vec = (vec+1)%4;
      }
      len -= 2;
    }
    if(len == 1){
      x += dx[vec];
      y += dy[vec];
      sharp[x][y] = true;
    }
    for(int p=0;p<n;p++){
      for(int q=0;q<n;q++){
	if(sharp[p][q]){
	  cout << "#";
	}else{
	  cout << " ";
	}
      }
      cout << endl;
    }
    isfirst = false;
  }
}