#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int n;
  char data[105][105];
  int dx[] = {0, 1, 0, -1};
  int dy[] = {-1, 0, 1, 0};
  int t;
  cin >> t;
  for(int tc=0;tc<t;tc++){
    cin >> n;
    if(tc != 0) cout << endl;
    if(n == 1){
      cout << "#" << endl;
      continue;
    }
    int y = n-1;
    int x = 0;
    fill(data[0], data[100], ' ');
    data[y][x] = '#';
    int d = 0;
    while(1){
      int ty = y + dy[d];
      int tx = x + dx[d];
      if(ty<0 || ty>=n){ d = (d+1)%4; continue; }
      if(tx<0 || tx>=n){ d = (d+1)%4; continue; }
      if(data[ty][tx] == '#') break;
      int tty = ty + dy[d];
      int ttx = tx + dx[d];
      if((tty>=0 || tty<n) && (ttx>=0 || ttx<n)){
	if(data[tty][ttx] == '#'){
	  d = (d+1)%4; 
	  continue; 
	}
      }
      int cnt = 0;
      for(int i=0;i<4;i++){
	int tty = ty + dy[i];
	int ttx = tx + dx[i];
	if(tty<0 || tty>=n) continue;
	if(ttx<0 || ttx>=n) continue;
	if(data[tty][ttx] == '#') cnt++;
      }
      if(cnt > 1) break;
      data[ty][tx] = '#';
      y = ty;
      x = tx;
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cout << data[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}