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

const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};
string g[102][100];

void init() {
  g[1][0] = "#";
  g[2][0] = "##";
  g[2][1] = "# ";
  for(int k = 3; k <= 100; ++k) {
    for(int i = 0; i < k-2; ++i) {
      g[k][i] = g[k-2][i];
    }
    for(int i = 0; i < k-2; ++i) {
      g[k][i] += " #";
    }
    g[k][k-2] = string(k, ' ');
    g[k][k-2][0] = g[k][k-2][k-1] = '#';
    g[k][k-1] = string(k, '#');
    for(int i = 0; i < k; ++i) {
      for(int j = 0; j < k; ++j) {
        if(make_pair(i,j) < make_pair(k-i-1,k-j-1)) {
          swap(g[k][i][j], g[k][k-i-1][k-j-1]);
        }
      }
    }
  }
}

int main() {
  init();
  int d;
  cin >> d;
  for(int tc = 0; tc < d; ++tc) {
    int n;
    cin >> n;
    if(tc) cout << endl;
    for(int i = 0; i < n; ++i) {
      cout << g[n][i] << endl;
    }
  }
  return 0;
}