#include<bits/stdc++.h>
int T,n,a[105][105];
int main()
{
scanf("%d",&T); for(int i=1,u,v,x,y;i<=T;++i)
{
scanf("%d",&n); if(n==1) {puts("."); continue; } !(u=n%6)&&(u+=6);
for(v=u,x=1;x<=n-u;x+=3) for(y=1;y<=n-u;y+=2) a[x][y]=a[x+1][y]=i;
if(v==3||v==6) {for(x=1;x<=n-u;x+=3) a[n-v+1][x]=a[n-v+1][x+1]=a[x][n-v+1]=a[x+1][n-v+1]=i; v-=2; }
if(v>=3) {for(x=1;x<=n-u;x+=2) a[n-v+1][x]=a[n-v+2][x]=a[x][n-v+1]=a[x][n-v+2]=i; v-=3; }
if(v==2) for(x=1;x<=n-u;x+=2) a[n-1][x]=a[n][x]=a[x][n-1]=a[x][n]=i;
if(v==1) for(x=1;x<=n-u;x+=3) a[n][x]=a[n][x+1]=a[x][n]=a[x+1][n]=i;
if(u==6) a[n-5][n-5]=a[n-5][n-4]=a[n-5][n-2]=a[n-4][n-2]=a[n-5][n]=a[n-4][n]=a[n-3][n-5]=a[n-3][n-4]=a[n-2][n-1]=a[n-2][n]=a[n-1][n-5]=a[n][n-5]=a[n-1][n-3]=a[n][n-3]=a[n][n-1]=a[n][n]=i;
else if(u==4) a[n-3][n-3]=a[n-3][n-2]=a[n-3][n]=a[n-2][n]=a[n-1][n-3]=a[n][n-3]=a[n][n-1]=a[n][n]=i;
else for(x=n-u+1;x<n;x+=3) for(y=n-u+1;y<=n;y+=2) a[x][y]=a[x+1][y]=i;
for(x=1;x<=n;++x,putchar('\n')) for(y=1;y<=n;++y) putchar(a[x][y]==i?'#':'.');
}
return 0;
}