#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
typedef long long int lint;
typedef vector< vector < char > > Mat;

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

void AOJ0141(bool newline)
{
	int n;
	cin >> n;

	if (newline) cout << endl;

	if (n == 1) {
		cout << "#" << endl;
		return;
	}
	if (n == 2) {
		cout << "##" << endl;
		cout << "# " << endl;
		return;
	}

	vector<int> steps;

	steps.push_back(n - 1);
	for (int i = n - 1; i > 0; i -= 2) {
		steps.push_back(i);
		steps.push_back(i);
	}
	if (n % 2 == 0) {
		steps.pop_back();
	}

	Mat spiral(n);
	REP(i, n) spiral[i] = vector<char>(n, ' ');
	int x = 0;
	int y = n - 1;

	spiral[y][x] = '#';

	REP(i, steps.size()) {
		REP(s, steps[i]) {
			x += dx[i % 4];
			y += dy[i % 4];
			spiral[y][x] = '#';
		}
	}

	REP(i, n) {
		REP(j, n) {
			cout << spiral[i][j];
		}
		cout << endl;
	}

	return;
}

int main()
{
	int d;
	cin >> d;

	bool newline = false;
	REP(i, d) {
		AOJ0141(newline);
		newline = true;
	}

	return 0;
}