#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int m;
bool isIn(int x, int y){
    return 0 <= x && x < m && 0 <= y && y < m;
}

int main(){
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    bool field[110][110];
    int n;
    cin >> n;
    for(int p=0; p < n; p++){
        if(p != 0) cout << endl;
        cin >> m;
        if(m == 1){cout << "#" << endl; continue;}
        else if(m == 2){cout << "##" << endl; cout << "# " << endl; continue;}
        rep(i, 110)rep(j, 110)field[i][j] = false;
        int x = 0, y = 0, d = 0;
        field[0][0] = true;
        while(true){
            bool change = false;
            while(isIn(x+dx[d], y+dy[d])){
                if(field[x+dx[d]][y+dy[d]]){
                    field[x][y] = false;
                    x -= dx[d]; y -= dy[d];
                    break;
                }
                change = true;
                x += dx[d]; y += dy[d];
                field[x][y] = true;
            }
            if(!change) break;
            d = (d+1)%4;
        }
        if(m%2 == 1){
            x += dx[d]; y += dy[d];
            field[x][y] = true;
        }

        for(int i=m-1; 0 <= i; i--){
            for(int j=0; j <= m; j++){
                cout << (field[i][j] ? "#" : " ");
            }
            cout << endl;
        }
    }
}