#include <iostream>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)
#define UP 0
#define RIGHT 1
#define DOWN 2
#define LIFT 3

using namespace std;

bool p[100][100];

void dfs (int len, int dir, int r, int c, int cnt )
{
	if (len <= 1 )
		return;

	dir = (dir + 1) % 4;
	if (cnt != 0 && cnt % 2 == 0 ){
		len -= 2;
	} // end if 

	int cr = r, cc = c;
	switch (dir ){
		case UP:
			for (int i = 0; i < len; i++, cr-- )
				p[cr][cc] = true;
			cr++;
			break;
		case DOWN:
			for (int i = 0; i < len; i++, cr++ )
				p[cr][cc] = true;
			cr--;
			break;	
		case RIGHT:
			for (int j = 0; j < len; j++, cc++ )
				p[cr][cc] = true;
			cc--;
			break;
		case LIFT:
			for (int j = 0; j < len; j++, cc-- )
				p[cr][cc] = true;
			cc++;
			break;
	} // end switch

	if (len == 2 )
		return;

	dfs (len, dir, cr, cc, cnt + 1 );
}

void disp_p (int m )
{
	rep (i, m ){
		rep (j, m ){
			if (p[i][j] )
				cout << '#';
			else
				cout << ' ';
		}// end rep
		cout << endl;
	} // end rep
}

int main()
{
	int n;

	while (cin >> n && n ){
		for (int i = 0; i < n; i++ ){
			int m;
			cin >> m;
			if (m == 1 ){
				cout << "#" << endl;
			}else if (m == 2 ){
				cout << "##" << endl;
				cout << '#' << endl;
			}else{
				memset (p, false, sizeof (p ) );
				for (int r = m - 1; r >= 0; r-- )
					p[r][0] = true;
				for (int c = 0; c < m; c++ )
					p[0][c] = true;
				for (int r = 0; r < m; r++ )
					p[r][m-1] = true;
				dfs (m-2, DOWN, m-1, m-1, 0 );
				disp_p (m );
			} // end if
		} // end if
	} // end whlie

	return 0;
}