#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#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 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;
        int m;
        cin >> m; m--;
        if(m == 0){cout << "#" << endl; continue;}
        else if(m == 1){cout << "##" << endl; cout << "#" << endl; continue;}
        rep(i, 110)rep(j, 110)field[i][j] = false;
        int x = 0, y = 0, d = 0;
        while(true){
            if(field[x+dx[d]][y+dy[d]]) break;
            int count = 0;
            for(int i=0; i< m && !field[x+dx[d]*2][y+dy[d]*2]; i++){
                count++;
                field[x][y]= true;
                x += dx[d]; y += dy[d];
                field[x][y] = true;
            }
            if(count == 1) break;
            d = (d+1)%4;
        }

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