#include <cstring>
#include <iostream>

using namespace std;

int n;
char pattern[104][104];

void rec(int d, bool c, int y, int x) {
  pattern[y][x] = '#';
  switch (d) {
  case 0:
    if (pattern[y-2][x] == '#')
      if (c && pattern[y+1][x+1] != '#') rec(1, false, y, x);
      else return;
    else
      rec(0, true, y-1, x);
    break;
  case 1:
    if (pattern[y][x+2] == '#')
      if (c && pattern[y+1][x-1] != '#') rec(2, false, y, x);
      else return;
    else
      rec(1, true, y, x+1);
    break;
  case 2:
    if (pattern[y+2][x] == '#')
      if (c && pattern[y-1][x-1] != '#') rec(3, false, y, x);
      else return;
    else
      rec(2, true, y+1, x);
    break;
  case 3:
    if (pattern[y][x-2] == '#')
      if (c && pattern[y-1][x+1] != '#') rec(0, false, y, x);
      else return;
    else
      rec(3, true, y, x-1);
    break;
  default:
    break;
  }
}

int main() {
  int d;
  cin >> d;
  for (int i = 0; i < d; i++) {
    memset(pattern, ' ', sizeof pattern);
    cin >> n;
    for (int j = 0; j < n+4; j++)
      pattern[0][j] = pattern[n+3][j] = pattern[j][0] = pattern[j][n+3] = '#';
    rec(0, true, n+1, 2);
    for (int y = 2; y < n+2; y++) {
      for (int x = 2; x < n+2; x++)
        cout << pattern[y][x];
      cout << endl;
    }
    if (i != d-1) cout << endl;
  }
}