#include <iostream>
#include <string>
#include <vector>

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

class Pos
{
public:
	int x, y;
};

void solve()
{
	int d;
	cin >> d;
	bool first = true;
	while(d--)
	{
		if(!first)
		{
			cout << endl;
		}
		first = false;
		int n;
		cin >> n;
		if(n == 1)
		{
			cout << "#" << endl;
			continue;
		}
		else if(n == 2)
		{
			cout << "##" << endl;
			cout << "#" << endl;
			continue;
		}
		vector< vector<char> > field(n, vector<char>(n));
		for(int i = 0; i < n; ++i)
		{
			field[i][0] = '#';
			field[i][n - 1] = '#';
			field[0][i] = '#';
		}
		int direction = 0;
		Pos current;
		current.x = n - 1;
		current.y = n - 1;
		while(true)
		{
			Pos next;
			next.x = current.x + dx[direction];
			next.y = current.y + dy[direction];
			int count = 0;
			while(field[next.y + dy[direction]][next.x + dx[direction]] != '#')
			{
				field[next.y][next.x] = '#';
				current = next;
				next.x = current.x + dx[direction];
				next.y = current.y + dy[direction];
				++count;
			}
			direction = (direction + 1) % 4;
			if(count < 2)
			{
				break;
			}
		}
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cout << field[i][j];
			}
			cout << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}