#include <iostream>
#include <vector>

using namespace std;

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

inline void next(int &d)
{
    d = (d + 1) % 4;
}

int main()
{
    int dataset, n;

    cin >> dataset;
    while (dataset--) {
        cin >> n;

        vector<vector<bool> > map(n, vector<bool>(n, false));
        int d = 0, x = 0, y = n - 1, l = n - 1;

        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < l; ++j) {
                map[y][x] = true;
                x += dx[d];
                y += dy[d];
            }
            next(d);
        }

        l -= 2;
        map[y][x] = true;
        for (int i = 0; i < n / 2; ++i) {
            for (int j = 0; j < l; ++j) {
                map[y][x] = true;
                x += dx[d];
                y += dy[d];
            }
            if (i % 2 != 0)
                l -= 2;
            map[y][x] = true;
            next(d);
         }

        // Output
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (map[i][j])
                    cout << "#";
                else
                    cout << " ";
            }
            cout << "\n";
        }
    }

    return 0;
}