#include<stdio.h>
#define N 500
int main(void)
{
  int v[N][N]={};
  int line=0;
  int line2=0;
  int i=0;
  int j=0;
  int a=1;
  int n=0;
  int k=0;

  scanf("%d", &n);
  while(k++<n)
    {
      scanf("%d", &line);

      line2=line;

      for (i=0;i<line;i++)
        {
          v[line][i]=2;
          v[0][i]=1;
        }

      while (line>=3)
        {
          for (i=2*(a-1);i<line;i++)
            {
              v[i][2*(a-1)]=1;
              v[line-1][i]=1;
            }

          for (;i>2*a+1;i--)
            {
              v[i-1][line-1]=1;
              v[2*a][i-1]=1;
            }

          a++;
          line-=2;
        }
      if((line2-6)%4==0)
        v[line2-2*(line2-2)/4-1][line2-2*(line2-2)/4-1]=0;

      for (j=0;j<line2;j++)
        for (i=0;i<=line2;i++)
          {
            switch (v[i][j])
              {
              case 0 : printf(" "); break;
              case 1 : printf("#"); break;
              case 2 : printf("\n"); break;
              }
            v[i][j]=0;
          }

      a=1;

    }

  return 0;
}