import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    val genTuple = (x: List[Int]) => {
      if (x.head > x.last) (x.sum, 0)
      else if (x.head < x.last) (0, x.sum)
      else (x.head, x.last)
    }

    val eachSum = (a: (Int, Int), b: (Int, Int)) => (a._1 + b._1, a._2 + b._2)

    val readIntList = (n: Int) => {
      var list: Array[List[Int]] = Array.empty
      for (i <- 0 until n) {
        list :+= readLine.split(' ').map(_.toInt).toList
      }
      list
    }

    while (true) {
      val n = readInt
      if (n == 0) return

      val result = readIntList(n).map(genTuple).foldLeft((0, 0))(eachSum)

      println(result._1 + " " + result._2)
    }
  }
}