#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int j = 0; j < n; j++) {
		int a;
		cin >> a;
		vector< vector<int> > uzu(a, vector<int>(a, 0));
		int ulimit, dlimit, rlimit, llimit;
		ulimit = 0;
		dlimit = a-1;
		rlimit = a-1;
		llimit = 2;
		int tate, yoko;
		tate = a-1;
		yoko = 0;
		if (a == 1) {
			uzu[0][0] = 1;
		}
		while (1) {
			if (yoko > rlimit || tate == ulimit) {
				break;
			}
			for (int i = tate; i >= ulimit; i--) {
				uzu[i][yoko] = 1;
			}
			tate = ulimit;
			ulimit += 2;
			if (tate > dlimit || yoko == rlimit) {
				break;
			}
			for (int i = yoko; i <= rlimit; i++) {
				uzu[tate][i] = 1;
			}
			yoko = rlimit;
			rlimit -= 2;
			if (yoko < llimit || tate == dlimit) {
				break;
			}
			for (int i = tate; i <= dlimit; i++) {
				uzu[i][yoko] = 1;
			}
			tate = dlimit;
			dlimit -= 2;
			if (tate < ulimit || yoko == llimit) {
				break;
			}
			for (int i = yoko; i >= llimit; i--) {
				uzu[tate][i] = 1;
			}
			yoko = llimit;
			llimit += 2;
		}
		if (j > 0) {
			cout << endl;
		}
		for (int i = 0; i < a; i++) {
			for (int k = 0; k < a; k++) {
				if (uzu[i][k] == 1) {
					cout << '#';
				} else {
					cout << ' ';
				}
			}
			cout << endl;
		}
	}
	return 0;
}