import qualified Data.Text as T
import qualified Data.Text.IO as TI
import Control.Applicative
import Control.Monad.Trans.Class
import Control.Monad.Trans.Maybe
import Control.Arrow
import Data.Maybe
import Control.Monad

read'::T.Text->Int
read'=read.T.unpack

game::(Num a,Ord a)=>(a,a)->(a,a)
game (a,b) = 
	if a > b then
		(a+b,0)
	else if a==b then
		(a,b)
	else
		(0,a+b)
		
tailMay::[a]->Maybe [a]	
tailMay (_:xs) = Just xs
tailMay [] = Nothing

add::Num a=>(a,a)->(a,a)->(a,a)
add (a,b) (c,d) = (a+c,b+d)

convert::Show a=>(a,a)->String
convert (a,b) = show a++" "++show b

(<$~>)::Functor f => f a -> (a -> b) -> f b 
(<$~>)=flip (<$>)
infixl 4 <$~>

checkMaybe::(a->Bool)->a->Maybe a
checkMaybe f v = if f v then Just v else Nothing

toTuple (a:b:[])=(a,b)
{-run::IO (Maybe ())
run = runMaybeT$
    lift TI.getContents<$~>
    T.lines>>=
    (MaybeT).return.checkMaybe ((/=T.pack "0").head)>>=
    (MaybeT).return.tailMay>>=
    fmap (T.split (==' '))<$~>
    fmap (fmap read')<$~>
    fmap toTuple<$~>return>>=
     (MaybeT).return.sequence>>=
    fmap game<$~>
    foldr add (0,0)<$~>
    convert<$~>return
    >>=lift.putStrLn-}
run = runMaybeT$ do{
	n<-read<$>lift getLine;
	if n==0 then 
		MaybeT$return$Nothing 
	else
		return ();
	lift (sequence (replicate n TI.getLine))<$~>
		fmap (T.split (==' '))<$~>
		fmap (fmap read')<$~>
		fmap toTuple<$~>
		fmap game<$~>
		foldr add (0,0)<$~>
		convert>>=
		lift.putStrLn;
}
whileMaybeM::Monad m=>m(Maybe a)->m ()
whileMaybeM f = do
	r<-f
	if isJust r then
		whileMaybeM f
	else
		return ()
main = whileMaybeM run