#include<iostream>
#include<string>
using namespace std;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i<n; i++) {
		int a, f;
		cin >> a;
		f = a*a;
		char b[100][100], c[100][100];
		for (int j = 0; j < a; j++) {
			for (int z = 0; z < a; z++) {
				b[j][z] = ' ';
				c[j][z] = ' ';
			}
		}
		int h = (a - 1), w = 0, h2 = -1, w2 = 0;
		b[h][w] = '#';
		c[h][w + 1] = '#';
		c[h][w] = '#';
		f -= 2;
		int k = 0;
		while (f >= 0) {
			if (h + h2 >= a || h + h2 < 0 || w + w2 >= a || w + w2 < 0 || c[h + h2][w+w2] == '#' ) {
				if (h2 == -1) {
					h2 = 0;
					w2 = 1;
				}
				else if (h2 == 1) {
					h2 = 0;
					w2 = -1;
				}
				else if (w2 == -1) {
					w2 = 0;
					h2 = -1;
				}
				else if (w2 == 1) {
					w2 = 0;
					h2 = 1;
				}
			}
			h += h2;
			w += w2;
			if (c[h][w] != '#')
				f--;
			b[h][w] = '#';
			c[h][w] = '#';
			if (h2 == -1) {
				if (c[h][w + 1] != '#')
					f--;
				c[h][w + 1] = '#';
			}
			else if (h2 == 1) {
				if (c[h][w - 1] != '#')
					f--;
				c[h][w - 1] = '#';
			}
			else if (w2 == -1) {
				if (c[h - 1][w] != '#')
					f--;
				c[h - 1][w] = '#';
			}
			else if (w2 == 1) {
				if (c[h + 1][w] != '#')
					f--;
				c[h + 1][w] = '#';
			}
			if (f == 0) {
				k++;
				if (k ==2) {
					f--;
				}
			}
			if (a % 2 == 1 && f == 0)
				break;
		}
		for (int i = 0; i<a; i++) {
			for (int j = 0; j<a; j++) {
				cout << b[i][j];
			}
			cout << endl;
		}
		if (i < n - 1)
			cout << endl;
	}
}