object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt)).toSeq.tail
    val x = in.map(r => {val nr = r :+ r.sum; println(nr.mkString(" ")); nr})
    println(x.transpose.map(_.sum).mkString(" "))
}