#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<vector<char>> v(n+2, vector<char>(n+2, 'X'));
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                v[i+1][j+1] = ' ';
            }
        }
        array<int, 4> dy{-1, 0, 1, 0}, dx{0, 1, 0, -1};
        int y = n, x = 1;

        for (int i = 0, dir = 0, a = 0; i < 2*n*n; ++i) {
            v[y][x] = '#';
            if(v[y+dy[dir]][x+dx[dir]] != ' ') dir = (dir+1)&3;
            else if(v[y+dy[dir]*2][x+dx[dir]*2] == '#') dir = (dir+1)&3;
            else {
                y += dy[dir];
                x += dx[dir];
            }
        }
        if(!(n&1)) v[n/2+1][n/2+1] = ' ';
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                cout << v[i+1][j+1];
            }
            puts("");
        }
        if(t) puts("");
    }
    return 0;
}
