main = getContents >>= main' . map (map read . words) . lines
    where
        main' ([x] : xs)
            | x /= 0 = return xs' >>= putStrLn . edit . solve >> main' xxs'
            | otherwise = return ()
            where
                (xs', xxs') = splitAt x xs

edit :: (Int, Int) -> String
edit (a, b) = show a ++ " " ++ show b

solve :: [[Int]] -> (Int, Int)
solve = foldl ff (0, 0)
    where
        ff (a, b) [x, y]
            | x > y = (a + x + y, b)
            | x < y = (a, b + x + y)
            | otherwise = (a + x, b + y)