def calc_game_result card_lines
  card_lines
    .lazy
    .map {|l| l.split(" ").map(&:to_i) }
    .map {|(a, b)|
      if a > b
        [a + b, 0]
      elsif a < b
        [0, a + b]
      else
        [a, b]
      end
    }
    .reduce([0, 0]) {|(a_ac, b_ac), (a_gain, b_gain)|
      [a_ac + a_gain, b_ac + b_gain]
    }
end

a_sum, b_sum = Enumerator.new {|y|
  until ((n = gets.to_i) == 0)
    y << n.times.map { gets }
  end
}
  .map{|lines| calc_game_result lines }
  .each {|(a_sum, b_sum)| puts "#{a_sum} #{b_sum}" }