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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	int a[101][101];
	int dx[4] = {0,1,0,-1};
	int dy[4] = {-1,0,1,0};
	
	bool first = true;

	rep(i,n)
	{
		int r;
		cin >> r;
		int r2 = r;

		memset(a,0,sizeof(a));

		if(r == 1)
		{
			if(first) first = false;
			else cout << endl;
			cout << "#" << endl;
		}
		else if(r == 2)
		{
			if(first) first = false;
			else cout << endl;
			cout << "##" << endl << "# " << endl;
		}
		else
		{
			int y = r-1;
			int x = 0;
			a[y][x] = 1;

			int dir = 0;

			rep(j,r-1)
			{
				y += dy[dir%4];
				x += dx[dir%4];
				a[y][x] = 1;
			}

			dir++;
			r--;
			
			if(r%2 == 1)
			{
				while(true)
				{
					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}
					dir++;

					if(r == 1) break;

					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}
					dir++;
					r -= 2;
				}
			}
			else
			{
				while(true)
				{
					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}
					dir++;

					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}

					if(r == 2 ) break;

					dir++;
					r -= 2;
				}
			}
			
			if(first) first = false;
			else cout << endl;

			rep(j,r2)
			{
				rep(k,r2)
				{
					if(a[j][k] == 1) cout << "#";
					else cout << " ";
				}
				cout << endl;
			}
		}	
	}
	return 0;
}