#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i,0,(n))
#define pb(n) push_back(n)
#define mp(n,m) make_pair(n, m)
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
int n;
vector<string> s;

bool outOfRange(int y, int x){
	if(y < 0 || y >= n || x < 0 || x >= n){
		return true;
	}
	return false;
}

bool check(int ny, int nx, int dir){
	if(outOfRange(ny, nx)) return true;
	for(int i = 0; i < 4; i++){
		if(i == (dir+2)%4) continue;
		int nny = ny + dy[i], nnx = nx + dx[i];
		if((!outOfRange(nny, nnx)) && s[nny][nnx] == '#'){
			return true;
		}
	}
	return false;
}

int main(){
	int d;
	cin>>d;
	for(int i = 0; i < d; i++){
		if(i!=0) printf("\n");
		cin>>n;
		s = vector<string>(n,string(n, ' '));
		pii pos = pii(n-1, 0);
		int dir = 0;
		while(1){
			if(s[pos.fi][pos.se]=='#') break;
			s[pos.fi][pos.se] = '#';
			int ny = pos.fi+dy[dir], nx = pos.se+dx[dir];
			int cnt = 4;
			while(check(ny, nx, dir) &&(--cnt)){
				dir++;
				dir%=4;
				ny = pos.fi+dy[dir]; nx = pos.se+dx[dir];

			}
			if(cnt == 0) break;
			pos=pii(ny ,nx);
		}
		rep(i, n){
			cout<<s[i]<<endl;
		}
	}
}