#include<iostream>
#include<cstring>

using namespace std;

const int MAX = 101;
char data[MAX][MAX];
int n;
int dx[4] = {0,1,0,-1};
int dy[4] = {-1,0,1,0};
 
void print(){
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(j) cout << " ";
      cout << data[i][j];
    }
    cout << endl;
  }
}

bool movable(int d, int x, int y){
  return data[y+dy[d]][x+dx[d]] == ' ';
}

void solve(){

  int x = 2,y = n-1;
  int d = 0;

  for(int i = 0; i < n; i++)
    data[0][i] = data[n-1][i] = data[i][0] = data[i][n-1] = '#';

  data[n-1][1] = ' ';

  while(1){
    int num = 0;

    while(1){
      x += dx[d];
      y += dy[d];
      if(movable(d,x,y)){
	num++;
	data[y][x] = '#';
      }else{
	x -= dx[d];
	y -= dy[d];
	break;
      }
    }
    if(num < 2) break;
    d++;
    d%=4;
  }
}

void init(){
  memset(data,' ',sizeof(data));
}

int main(){

  bool line = false;
  int x;
  cin >> x;
  
  while(x--){
    if(line) cout << endl;
    line = true;
    init();
    cin >> n;
    solve();
    print();
  }
  return 0;
}