#include<iostream>
#include<string>
#include<vector>
#define X '#'

using namespace std;

vector<string> Init(int);
void DrawSpiral(vector<string>&, int);
int DrawTopLine(vector<string>&, int&, int&, int);
int DrawBottomLine(vector<string>&, int&, int&, int);
int DrawLeftLine(vector<string>&, int&, int&, int);
int DrawRightLine(vector<string>&, int&, int&, int);

int main(){
  int i, j, n, m;
  vector<string> data;

  cin >> n;

  for(i=0; i<n; ++i){
    cin >> m;
    data = Init(m);
    DrawSpiral(data, m);

    for(j=0; j<data.size(); ++j)
      cout << data[j] << endl;

    if(i != n-1) cout << endl;
  }
  return 0;
}

vector<string> Init(int n){
  const string str(n, ' ');
  vector<string> data;
  for(int i=0; i<n; ++i) data.push_back(str);
  return data;
}

void DrawSpiral(vector<string>& data, int n){
  if(n == 1){
    data[0][0] = X;
    return;
  }
  if(n == 2){
    data[0][0] = X;
    data[1][0] = X;
    data[0][1] = X;
    return;
  }

  int i, j;
  i = n-1;
  j = 0;
  while(1){
    if(DrawLeftLine(data, i, j, n) == 1) return;
    if(DrawTopLine(data, i, j, n) == 1) return;
    if(DrawRightLine(data, i, j, n) == 1) return;
    if(DrawBottomLine(data, i, j, n) == 1) return;
  }
}

int DrawTopLine(vector<string>& data, int& i, int& j, int n){
  if(j == n-1 || (j <= n-3 && data[i][j+2] == X)) return 1;
  if(n%2 == 0 && data[i][j+3] == X){
    data[i][j+1] = X;
    return 1;
  }
  while(j <= n-1 && data[i][j+2] != X){
    data[i][j] = X;
    if(j == n-1 || (j <= n-3 && data[i][j+2] == X)) return 0;
    ++j;
  }
  return 0;
}

int DrawBottomLine(vector<string>& data, int& i, int& j, int n){
  if(j == 0 || (j >= 2 && data[i][j-2] == X)) return 1;
  if(n%2 == 0 && data[i][j-3] == X){
    data[i][j-1] = X;
    return 1;
  }
  while(j >= 0 && data[i][j-2] != X){
    data[i][j] = X;
    if(j == 0 || (j >= 2 && data[i][j-2] == X)) return 0;
    --j;
  }
}

int DrawLeftLine(vector<string>& data, int& i, int& j, int n){
  if(i == 0 || (i >= 2 && data[i-2][j] == X)) return 1;
  if(n%2 == 0 && data[i-3][j] == X){
    data[i-1][j] = X;
    return 1;
  }
  while(1){
    data[i][j] = X;
    if(i == 0 || (i >= 2 && data[i-2][j] == X)) return 0;
    --i;
  }
}

int DrawRightLine(vector<string>& data, int& i, int& j, int n){
  if(i == n-1 || (i <= n-3 && data[i+2][j] == X)) return 1;
  if(n%2 == 0 && data[i+3][j] == X){
    data[i+1][j] = X;
    return 1;
  }
  while(1){
    data[i][j] = X;
    if(i == n-1 || (i <= n-3 && data[i+2][j] == X)) return 0;
    ++i;
  }
}