#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char field[101][101];
int N, n, now;
int x, y;
bool flag;

void print(){
  for(int i = 0 ; i <= n ; i++){
    for(int j = 0 ; j <= n ; j++){
      cout << field[i][j];
    }
    cout << endl;
  }
}

void init(){
  flag = false;
  for(int i = 0 ; i < 101 ; i++){
    for(int j = 0 ; j < 101 ; j++){
      field[i][j] = ' ';
    }
  }
  for(int i = n ; i >= 0 ; i--){
    field[i][0] = '#';
  }
  for(int i = 0 ; i < n ; i++){
    field[0][i] = '#';
  }
  for(int i = 0 ; i <= n ; i++){
    field[i][n] = '#';
  }
}

void left(){
  int j;
  for(j = x ; field[y][j-1] != '#' ; j--){
    field[y][j] = '#';
  }
  x = j+1;
}

void up(){
  int i;
  for(i = y ; field[i-1][x] != '#' ; i--){
    field[i][x] = '#';
  }
  y = i+1;
}

void right(){
  int j;
  for(j = x ; field[y][j+1] != '#' ; j++){
    field[y][j] = '#';
  }
  x = j-1;  
}

void down(){
  int i;
  for(i = y ; field[i+1][x] != '#' ; i++){
    field[i][x] = '#';
  }
  y = i-1;
}

    
int main(){
  cin >> N;
  for(int cs = 0 ; cs < N ; cs++){
    cin >> n;
    n--;
    
    if(n == 0) cout << '#' << endl << endl;
    else if(n == 1){
      cout << "##" << endl << "# " << endl << endl;
    }
    else{
    init();
    x = n, y = n;
    int cnt = 3;
    while(1){
      if(cnt == n+1) break;
      left();
      cnt++;
      if(cnt == n+1) break;
      up();
      cnt++;
      if(cnt == n+1) break;
      right();
      cnt++;
      if(cnt == n+1) break;
      down();
      cnt++;
    }
    print();
    if(cs != N-1) cout << endl;
    }
  } 
  return 0;
}
    

    
    