#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
	int n, s, t = 0, x, y, m, l;
	char a[104][104];
	cin >> l;
	
	while(l--){
		cin >> n;
		if(t == 1){
			cout << endl;
		} else if(n == 1){
			cout << "#" << endl;
			t = 1;
		}
		fill(&a[0][0], &a[n+4][n+4], ' ');
		s = 2;
		t = n+1;
		m = n;
		x = 1;
		y = -1;
		while(m--){
			while(t <= n+1 && t >= 2){
				a[t][s] = '#';
				if(y < 0){
					if(a[t-2][s] == '#'){
						t += y;
						break;
					}
				} else {
					if(a[t+2][s] == '#'){
						t += y;
						break;
					}
				}
				t += y;
			}
			if(m-- == 0){
				break;
			}
			t -= y;
			y = -y;
			while(s <= n+1 && s >= 2){
				a[t][s] = '#';
				if(x < 0){
					if(a[t][s-2] == '#'){
						s += x;
						break;
					}
				} else {
					if(a[t][s+2] == '#'){
						s += x;
						break;
					}
				}
				s += x;
			}
			s -= x;
			x = -x;
		}
		n++;
		for(int i = 2; i <= n; i++){
			for(int j = 2; j <= n; j++){
				cout << a[i][j];
			}
			cout << endl;
		}
		t = 1;
	}
	
	return 0;
}