#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

char maze[110][110];
int dx[] = {0,1,0,-1} , dy[] = {-1,0,1,0};
int size;

bool over(int x,int y){
  return x < 0 || size <= x || y < 0 || size <= y;
}
bool space(int x,int y){
  int cnt = 0;
  rep(i,4){
    int nx = x + dx[i], ny = y + dy[i];
    if(maze[ny][nx] == '#')
      cnt ++;
  }
  return cnt > 1;
}
void dfs(int x,int y,int d){
  if(size <= x) 
    dfs(x-1,y,2);
  if(y < 0)
    dfs(x,y+1,1);
  if(size <= y)
    dfs(x,y-1,3);
  if(space(x,y))
    return ;
  if(over(x,y))return;
  maze[y][x] = '#';
  
  int nnx = x + 2 * dx[d] , nny = y + 2 * dy[d];
  if(maze[nny][nnx] == '#')
    d = (d+1)%4;
  dfs(x+dx[d],y+dy[d],d);

}

void solve(int n){
  size = n;
  dfs(0,n-1,0);
  rep(i,n){
    rep(j,n){
      cout<<maze[i][j];
    }
    cout<<endl;
  }
}

int main(void){
  int n,in;
  cin>>n;
  rep(time,n){
    cin>>in;
    rep(i,in)rep(j,in)maze[i][j] = ' ';
    solve(in);
   
    if(!time)cout<<endl;
  }
}