require'matrix'
v=Vector
puts$<.drop(1).map{|n|r=1..n=n.to_i
#h=Hash.new{|_,u|u.min>0&&u.max<=n}
#x=v[n,1]
#u=x/n
#m=Matrix[[0,1],-u]
#h[x-m*u],x=h[x-u]?$Z:u=m*u,x-u while h[x]
r.map{|i|r.map{|j|h[v[i,j]]??#:' '}*''}*"\n"}*"\n\n"
