#include <iostream>

using namespace std;

int xdir[4] = {0, 1, 0, -1}, ydir[4] = {-1, 0, 1, 0}, d;
char a[100][100];

bool check(int x, int y)
{
  int cnt = 0;
  for(int i = 0; i < 4; i++){
    int dx = x+xdir[i], dy = y+ydir[i];
    if(a[dy][dx] == '#') cnt++;
  }

  return cnt == 1;
}

void func(int x, int y, int dr)
{
  int dx = x+xdir[dr], dy = y+ydir[dr];
  int tx = x+2*xdir[dr], ty = y+2*ydir[dr];
  a[y][x] = '#';

  if((dx < 0 || dy < 0 || dx == d || dy == d)){
    int td = (dr+1)%4;
    dx = x+xdir[td]; dy = y+ydir[td];
    if(dx < 0 || dy < 0 || dx == d || dy == d) return ;
    tx = x+2*xdir[td]; ty = y+2*ydir[td];
    if(tx >= 0 && tx < d && ty >= 0 && ty < d && a[ty][tx] == ' ') func(dx, dy, td);
  } else if(tx >= 0 && tx < d && ty >= 0 && ty < d && a[ty][tx] == '#'){
    int td = (dr+1)%4;
    dx = x+xdir[td]; dy = y+ydir[td];
    tx = x+2*xdir[td]; ty = y+2*ydir[td];
    if(tx >= 0 && tx < d && ty >= 0 && ty < d && a[ty][tx] == '#') return ;
    if(check(dx, dy)) func(dx, dy, td);
  } else {
    func(dx, dy, dr);
  }

  return ;
}

int main()
{
  int n;
  bool f = false;

  while(cin>>n)
    while(n--){
      cin >> d;
      if(f) cout << endl;
      f = true;
      
      for(int i = 0; i < 100; i++)
	for(int j = 0; j < 100; j++) a[i][j] = ' ';
      
      func(0, d-1, 0);
      
      for(int i = 0; i < d; i++){
	for(int j = 0; j < d; j++) cout << a[i][j];
	cout << endl;
      }
    }
  
  return 0;
}