object Main {
  def main(args: Array[String]) {

    var SEP = "####################"

    var housemap: Seq[Seq[Seq[Int]]] = Seq(
      Seq(Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
      Seq(Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
      Seq(Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
      Seq(Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)))

    var input: List[String] = List()
    for (line <- scala.io.Source.stdin.getLines()) {
      input = input :+ line
    }
    input = input.slice(1, input.length)

    input.foreach { list =>

      var Array(b, f, r, v) = list.split(' ').map(_.toInt)
      var a1a: Seq[Seq[Seq[Int]]] = Seq()

      housemap.zipWithIndex.foreach {
        case (b1, b1idx) =>
          var a1: Seq[Seq[Int]] = Seq()

          b1.zipWithIndex.foreach {
            case (listtt, b2idx) if (b1idx == (b - 1) && b2idx == (f - 1)) => {
              a1 = a1 :+ listtt.updated(r-1, if ((listtt(r) + v) < 9) (listtt(r) + v) else 9)
            }
            case (listtt, b2idx) => { a1 = a1 :+ listtt }
          }
          a1a = a1a :+ a1
      }
      housemap = a1a
    }

    var stgs: Seq[String] = Seq()
    housemap.foreach { v =>
      var lines: Seq[String] = Seq()
      v.foreach { f =>
        lines = lines :+ f.mkString(" ")
      }
      stgs = stgs :+ lines.mkString("\n")
    }
    println(stgs.mkString("\n" + SEP + "\n"))
  }

}