import scala.math.{min,max}

object Main {
  val sc = new java.util.Scanner(System.in);
  def main(args: Array[String]) {
    val d = sc.nextInt()
    for(i <- 1 to d) {
      var n = sc.nextInt()
      val m = Array.ofDim[Char](n, n)
      for(j <- 0 until n) {
        for(k <- 0 until n) {
          m(j)(k) = ' '
        }
      }
      var x, y = 0
      while(n > 0) {
        n match {
          case 1 => {
            m(x)(y) = '#'
          }
          case 2 => {
            m(x+0)(y+0) = '#'
            m(x+1)(y+0) = '#'
            m(x+1)(y+1) = '#'
          }
          case 3 => {
            for(j <- 0 to 2) {
              m(x+j)(y+0) = '#'
              m(x+j)(y+2) = '#'
              m(x+2)(y+j) = '#'
            }
          }
          case 4 => {
            for(j <- 0 to 3) {
              m(x+j)(y+0) = '#'
              m(x+j)(y+3) = '#'
              m(x+3)(y+j) = '#'
            }
            m(x)(y+2) = '#'
          }
          case _ => {
            for(j <- 0 until n) {
              m(x+j)(y) = '#'
              m(x+j)(y+n-1) = '#'
              m(x+n-1)(y+j) = '#'
            }
            for(j <- 2 until n) {
              m(x)(y+j) = '#'
            }
            m(x+1)(y+2) = '#'
          }
        }
        x = x+2
        y = y+2
        n = n-4
      }
      m.reverse.foreach(a => println(a.mkString("")))
    }
  }
}