
object Main extends App {
  import scala.io.StdIn.{readLine}
  println((0 until readLine().toInt).map{_ ⇒
    val field = FillSpiral(readLine().toInt)
    (0 until field.size).map{y ⇒ (0 until field.size).map{x ⇒ field(x, y)}.mkString}.mkString("","\n", "")
  }.mkString("","\n\n",""))
  case class Coordinate(x:Int, y:Int){
    def +(other:Coordinate):Coordinate = Coordinate(x + other.x, y + other.y)
  }
  class Field(val size:Int){
    private val mArray = Array.tabulate(size){_ ⇒ Array.tabulate(size){_ ⇒ ' '}}
    def apply(x:Int, y:Int):Char = mArray(x)(y)
    def apply(coordinate: Coordinate):Char = mArray(coordinate.x)(coordinate.y)
    def update(x:Int, y:Int, value:Char):Unit = mArray(x)(y) = value
    def update(coordinate: Coordinate, value:Char):Unit = mArray(coordinate.x)(coordinate.y) = value
  }
  object Field{
    def apply(size:Int):Field = new Field(size)
  }
  def FillSpiral(size:Int):Field = {
    val field = Field(size)
    var leftTop = Coordinate(0, 0)
    var rightBottom = Coordinate(size - 1, size - 1)
    while (leftTop.x <= rightBottom.x){
      for (x ← leftTop.x to rightBottom.x){
        field(x, leftTop.y) = '#'
      }
      for (y ← leftTop.y to rightBottom.y){
        field(leftTop.x, y) = '#'
      }
      if (leftTop.y + 1 < rightBottom.y) for (x ← (leftTop.x + 2) to rightBottom.x){
        field(x, rightBottom.y) = '#'
      }
      if (leftTop.x + 1 < rightBottom.x) for (y ← leftTop.y to rightBottom.y){
        field(rightBottom.x, y) = '#'
      }
      if (leftTop.y + 3 <= rightBottom.y && leftTop.x + 4 <= rightBottom.x) field(leftTop.x + 2, rightBottom.y - 1) = '#'
      leftTop = Coordinate(2, 2) + leftTop
      rightBottom = Coordinate(-2, -2) + rightBottom
    }
    field
  }
}

