#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int h, w;

bool can(int y, int x){
	return (0 <= y && y < h && 0 <= x && x < w);
}

int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

signed main() {
	int t, n;
	cin >> t;
	rep(k, 0, t){
		if(k) cout << endl;
		int a[110][110]={};
		cin >> n;
		h = w = n;
		vi d;
		int tmp = n;
		d.push_back(tmp);
		while(1){
			if(tmp <= 2){
				d.push_back(tmp);
				break;
			}
			rep(i,0,2) d.push_back(tmp);
			tmp -= 2;
		}
		int y = n - 1, x = 0;
		a[y][x] = 1;
		rep(i, 0, d.size()){
			int dir = i % 4;
			rep(j, 0, d[i] - 1){
				y += dy[dir];
				x += dx[dir];
				a[y][x] = 1;
			}
		}
		rep(i, 0, n){
			rep(j, 0, n){
				cout << (a[i][j] ? "#":" ") ;
			}
			cout << endl;
		}
	}
}