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

int n;
char c[999][999];
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};

bool chk(int y, int x){
  if(y > -1 && x > -1 && y < n+2 && x < n+2 && c[y][x] != ' ') return true;
  return false;
}

void solve(int y, int x, int p){

  int py = y + dy[p], px = x + dx[p];
  int pyy = y + dy[p]*3, pxx = x + dx[p]*3;
  
  if(n == 1){ c[y][x] = '#'; return; }
  if(y < 0 || x < 0 || y == n || x == n || c[y][x] != ' ') return;
  for(int i=0;i<4;i++) if(c[py][px] != ' ' && (i+2)%4 != p) return;
  
  c[y][x] = '#';
  
  if((!py || chk(pyy, pxx)) && !p) p++;
  else if((px == n-1 || chk(pyy, pxx)) && p == 1) p++;
  else if((py == n-1 || chk(pyy, pxx)) && p == 2) p++;
  else if((!px || chk(pyy, pxx)) && p == 3) p = 0;
  
  solve(py, px, p);
}

int main(){

  int l;
  cin >> l;
  while(l--){
    memset(c, ' ', sizeof(c));
    cin >> n;
    solve(n-1,0,0);
    for(int i=0;i<n;i++) c[i][n] = '\0', cout << c[i] << endl;
  }
}