#include <iostream>
#include <vector>
#include <string>
using namespace std;

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

void debug(vector<string> m){
	for(int y=0 ; y < n ; y++ ){
		for(int x=0 ; x < n ; x++ ){
			cout << m[y][x];
		}
		cout << endl;
	}
}

void solve(){
	vector<string> m(n);
	for(int y=0 ; y < n ; y++ ){
		for(int x=0 ; x < n ; x++ ){
			m[y].push_back(' ');
		}
	}
	int x = 0, y = n-1, d=0;
	m[y][x] = '#';
	int cnt=0;
	while( cnt < 4 ){
		int mx, my;
		bool flag = false;
		for(int i=-1 ; i <= 1 ; i++ ){
			mx = x + dx[d%4];
			my = y + dy[d%4];
			mx = mx + dx[(d-i+4)%4];
			my = my + dy[(d-i+4)%4];
			if( mx >= 0 && my >= 0 && mx < n && my < n && m[my][mx] == '#' ){
				flag = true;
			}
		}
		if( flag ){
			d = (d + 1) % 4;
			cnt++;
			continue;
		}
		
		mx = x + dx[d%4];
		my = y + dy[d%4];
		if( mx < 0 || my < 0 || mx >= n || my >= n ){
			d = (d + 1) % 4;
			cnt++;
			continue;
		}
		m[my][mx] = '#';
		x = mx;
		y = my;
		cnt = 0;
	}
	for(int y=0 ; y < n ; y++ ){
		cout << m[y] << endl;
	}
}

int main(){
	int d;
	cin >> d;
	for(int t=0 ; t < d ; t++ ){
		cin >> n;
		solve();
		if( t != d-1 ){
			cout << endl;
		}
	}
}