#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

typedef vector<string> vs;

int n;

bool check(int x, int y) {
	return x >= 0 && x < n && y >= 0 && y < n;
}

int main() {
	int N;
	cin >> N;
	while (N--) {
		cin >> n;
		vs str(n);
		REP(i, n) str[i].resize(n, ' ');
		
		int dx[4] = { 0, 1, 0, -1 };
		int dy[4] = { -1, 0, 1, 0 };
		int nx = 0, ny = n - 1, d = 0, cnt = 0;
		
		while (true) {
			if (cnt == n) break;
			str[ny][nx] = '#';
			
			if (!check(nx + dx[d], ny + dy[d]) ||
				(check(nx + dx[d]*2, ny + dy[d]*2) && str[ny + dy[d]*2][nx + dx[d]*2] == '#') ) {
				d = (d + 1) % 4;
				cnt++;
			}
			else {
				nx += dx[d]; ny += dy[d];
			}
		}
		
		REP(i, n) cout << str[i] << endl;
		if (N != 0) putchar('\n');
	}
	return 0;
}