#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

void solve(char a[105][105], int inp, int d, int y, int x){
    int i;
    for(i = 0; i < inp - 1; i++){
        a[y][x] = '#';
        if(d == 0){
            if(a[y - 2][x] == '#') break;
            y--;
        }else if(d == 1){
            if(a[y][x + 2] == '#') break;
            x++;
        }else if(d == 2){
            if(a[y + 2][x] == '#') break;
            y++;
        }else{
            if(a[y][x - 2] == '#') break;
            x--;
        }
    }
    if(i <= 1) return;
    solve(a, inp, (d + 1) % 4, y, x);

}

int main(){
    int n;
    char a[105][105];
    cin >> n;
    rep(i,n){
        rep(i,105) rep(j,105) a[i][j] = ' ';
        int inp;
        cin >> inp;
        solve(a, inp, 0, 104, 0);
        for(int i = 104 - inp; i <= 104; i++){
            rep(j,inp){
                cout << a[i][j];
            }
            cout << endl;
        }
    }
}