
import std.stdio, std.typecons, std.string, std.conv;

enum D {up, bottom, left, right};

void show(char[][] field, int n) {
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++)
      writef("%c%s", field[i][j], (j == (n - 1)) ? "\n" : " ");
  writeln;
}

char[][] draw_spiral(char[][] field, int n) {
  D direction = D.up;
  int[] pos = [n - 1, 0];
  int len = n;
  bool first = true;
  if (n == 1) {field[0][0] = '#'; return field;}
  if (n == 2) {
    field[0][0] = '#';
    field[0][1] = '#';
    field[1][1] = '#';
    field[1][0] = '#';
    return field;
  }
  foreach(ref f; field)
    foreach(ref x; f) x = ' ';
  while(true) {
    switch(direction) {
    case D.up:
      if (len <= 2) goto end;
      for(int i = 0; i < len; i++) field[pos[0] - i][pos[1]] = '#';
      pos = [pos[0] - (len - 1), pos[1]];
      direction = D.right;
      if (!first) len -= 2;
      break;
    case D.right:
      if (len <= 1) goto end;
      for(int i = 0; i < len; i++) field[pos[0]][pos[1] + i] = '#';
      pos = [pos[0], pos[1] + (len - 1)];
      direction = D.bottom;
      break;
    case D.bottom:
      if (len <= 2) goto end;
      for(int i = 0; i < len; i++) field[pos[0] + i][pos[1]] = '#';
      pos = [pos[0] + (len - 1), pos[1]];
      direction = D.left;
      len -= 2;
      break;
    case D.left:
      if (len <= 1) goto end;
      for(int i = 0; i < len; i++) field[pos[0]][pos[1] - i] = '#';
      pos = [pos[0], pos[1] - (len - 1)];
      direction = D.up;
      break;
    default:
      throw new Exception("illegal direction");
      break;
    }
    if (first) first = false;
  }
 end:;
  return field;
}

int read_num() {return readln.chomp.to!(int);}

void main() {
  int n = read_num;
  foreach(i; 0..n) {
    int size = read_num;
    draw_spiral(new char[][](size, size), size).show(size);
  }
}