#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int dy[] = {-1, 0, 1, 0};
    int dx[] = {0, 1, 0, -1};

    int d;
    cin >> d;

    bool first = true;
    while(--d >= 0){
        if(first)
            first = false;
        else
            cout << endl;

        int n;
        cin >> n;

        int len = n-1;
        int num = 3;
        int y = n-1;
        int x = 0;
        int i = 0;
        vector<string> s(n, string(n, ' '));
        s[y][x] = '#';

        for(;;){
            for(int j=0; j<len; ++j){
                y += dy[i];
                x += dx[i];
                s[y][x] = '#';
            }
            (++i) %= 4;
            if(--num == 0){
                num = 2;
                len -= 2;
            }
            if(n % 2 == 0 && num == 1 && len == 1)
                break;
            if(n % 2 == 1 && len == 0)
                break;
        }

        for(int i=0; i<n; ++i)
            cout << s[i] << endl;
    }

    return 0;
}