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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int nn;
  cin >> nn;
  REP(datan,nn) {
    int n;
    cin >> n;
    
    char c[n][n];
    memset(c,' ',sizeof(c));
    if (n==2) c[1][0] = '#';
    int dx[] = {0,1,0,-1};
    int dy[] = {-1,0,1,0};

    int x = 0, y = n - 1;

    c[x][y] = '#';
    int h = n-1;
    int d = 0;
    int j = 0;
    while(h>0) {
      REP(i,h) {
        x += dx[d];
        y += dy[d];
        c[x][y]=  '#';
      }

      if (h==1) break;
      d = (d+1)%4;
      if (j>=2 && j%2==0)
        h-=2;
      j++;
    }
    if (datan) cout << endl;
    REP(y,n) {
      REP(x,n) {
        cout << c[x][y];
      }
      cout << endl;
    }
  }
}