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

void draw(int width, int x, int y, vector<string>& a) {
    if (width == 1) {
        a[x][y] = '#';
    } else if (width == 2) {
        a[x][y] = a[x+1][y] = a[x][y+1] = '#';
    } else if (width == 3) {
        a[x][y] = a[x][y+1] = a[x][y+2] = '#';
        a[x+1][y] = a[x+1][y+2] = '#';
        a[x+2][y] = a[x+2][y+2] = '#';
    } else if (width == 4) {
        a[x][y] = a[x][y+1] = a[x][y+2] = a[x][y+3] = '#';
        a[x+1][y] = a[x+1][y+3] = '#';
        a[x+2][y] = a[x+2][y+3] = '#';
        a[x+3][y] = a[x+3][y+2] = a[x+3][y+3] = '#';
    } else {
        for (int j = 0; j < width; ++j) {
            a[x][y+j] = '#';
        }
        for (int j = 1; j < width; ++j) {
            a[x+j][y] = '#';
            a[x+j][y+width-1] = '#';
        }
        for (int j = 2; j < width; ++j) {
            a[x+width-1][y+j] = '#';
        }
        a[x+width-2][y+2] = '#';
        draw(width-4, x+2, y+2, a);
    }
}

int main() {
    int N;
    cin >> N;
    for (;N--;) {
        int W;
        cin >> W;
        vector<string> a(W, string(W, ' '));

        draw(W, 0, 0, a);
        for (int j = 0; j < W; ++j) {
            cout << a[j] << endl;
        }
        if (N > 0) {
            cout << endl;
        }
    }
    return 0;
}