import scala.io.StdIn._
import scala.collection.mutable

object Main {
  def main(args: Array[String]) {
    val (buildings, floors, rooms) = (4, 3, 10)
    val officailHouseInfo: mutable.ListBuffer[(Int, Int)] =
      mutable.ListBuffer(
        (for(b <- 1 to buildings; f <- 1 to floors; r <- 1 to rooms)
          yield (s"$b$f$r".toInt, 0)): _*)

    def updateOfficialHouseInfo(limit: Int, i:Int = 0): Unit ={
      if(i < limit) {
        val Array(b, f, r, v) = readLine().split(" ")
        val room = (b + f + r).toInt
        val findRoomIndex = officailHouseInfo.indexWhere(_._1 == room)
        officailHouseInfo(findRoomIndex) = (room, officailHouseInfo(findRoomIndex)._2 + v.toInt)

        updateOfficialHouseInfo(limit, i + 1)
      }
    }

    updateOfficialHouseInfo(readInt())
    val officailHouseInfoValue = for((i, j) <- officailHouseInfo) yield j

    var i = 1
    officailHouseInfoValue.foreach { value =>
      if(i % (floors * rooms) == 0 &&
        i < buildings * floors * rooms) print(" " + value + "\n####################\n")
      else if(i % rooms == 0) print(" " + value + "\n")
      else print(" " + value)
      i += 1
    }
  }
}