#include <iostream>
#include <algorithm>
using namespace std;

char A[100][100];

int main() {
    int D; cin >> D;
    while(D--) {
        int N; cin >> N;
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                A[i][j] = ' ';
            }
        }
        int x = 0, y = N;
        const int dx[] = { 0, 1, 0, -1 };
        const int dy[] = { -1, 0, 1, 0 };
        int dir = 0;
        for(int i = 0; i < N; i++) {
            int k;
            if(i == 0) k = N;
            else k = N + 1 - (i + 1) / 2 * 2;

            for(int j = 0; j < k; j++) {
                x += dx[dir]; y += dy[dir];
                A[y][x] = '#';
            }
            (dir += 1) %= 4;
        }
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                cout << A[i][j];
            }
            cout << endl;
        }
        if(D != 0) cout << endl;
    }
}