Go: package main

import "fmt"

func main() {
	for {
		var a, b, n int
		fmt.Scanf("%d", &n)

		if n == 0 {
			return
		}

		for i := 0; i < n; i++ {
			var cardA, cardB int
			fmt.Scanf("%d %d", &cardA, &cardB)

			if cardA > cardB {
				a += cardA + cardB
			} else if cardB > cardA {
				b += cardA + cardB
			} else {
				a += cardA
				b += cardB
			}
		}

		fmt.Println(a, b)
	}
}

Python: while True:
    n = int(input())
    if n == 0:
        break
    a = 0
    b = 0
    for i  in range(n):
        cardnum = [int(i) for i in input().split()]
        if cardnum[0] < cardnum[1]:
            b += sum(cardnum)
        elif cardnum[0] > cardnum[1]:
            a += sum(cardnum)
        else:
            a += cardnum[0]
            b += cardnum[1]
print(a,b)

Python: N=[]
T=[]
while True:
    n = input().split()
    for e in n:
        N += [int(e)]
    if len(n) == 1 and N[-1] == 0:
        break

T += [N.pop(0)]
while T[-1] != 0:
    T += [N.pop(sum(T)*2)]

for t in T:
    if t == 0:
        break
    A = 0
    B = 0
    f = N[:t*2]
    del N[:t*2]
    for n in range(t):
        g = 2*n
        if f[g] > f[g+1]:
            A += f[g]+f[g+1]
        elif f[g] < f[g+1]:
            B += f[g]+f[g+1]
        else:
            A += f[g]
            B += f[g+1]
    print (A,B)

Python: # coding: utf-8
# Here your code !

n = int(input())

while n!=0 :
    #1??????????????¨?????????
    pointA=0
    pointB=0
    for i in range(n):
        x = list(map(int, input().split()))
        if x[0] == x[1]:
            pointA += x[0]
            pointB += x[1]
        elif x[0] > x[1]:
            pointA += x[0] + x[1]
        else:
            pointB += x[0] + x[1]
    
    print(pointA, pointB)
    n = int(input())

Python: while 1:
    A=[]
    B=[]
    n=int(input())
    
    if n==0:
        break

    else:
        for i in range(n):
            d=map(int,input().split(' '))
            D=list(d)


            if D[0]>D[1]:
                A.append(D[0])
                A.append(D[1])
                

            elif D[0]==D[1]:
                A.append(D[0])
                B.append(D[1])

            else:
                B.append(D[0])
                B.append(D[1])


    AP=sum(A)
    BP=sum(B)

    print(AP,BP)
                
                
                
            
    
    #print (A,B)

Python: while True:
    n = int(input())
    if n == 0:
        break
    A, B = 0, 0
    for _ in range(n):
        x, y = map(int, input().split())
        if x > y:
            A += x + y
        elif x < y:
            B += x + y
        else:
            A += x
            B += y
    print(A, B)

Python: n = int(input())
A = 0
B = 0
for i in range(n):
    a,b = map(int,input().split())
    if a > b:A += a + b
    elif a < b:B += a + b
    else:
        A+=a
        B+=b
print(A,B)

Python: 
def battle_A_B(A,B):
	A_points = 0
	B_points = 0
	for i in range(len(A)):
		A_idx = int(A[i])
		B_idx = int(B[i])
		if A_idx > B_idx:
			A_points += (A_idx+B_idx)
		elif A_idx < B_idx:
			B_points += (A_idx+B_idx)
		else:	
			A_points += A_idx
			B_points += B_idx	
	insert = str(A_points)+" "+str(B_points) #+"\n"
	insert_list.append(insert)


insert_list = []
while(1):
	num = input()
	num = num.rstrip("\n")
	num_list = num.split(" ")
	if len(num_list) == 1:
		if int(num_list[0]) == 0:
			break
		battle_num = int(num_list[0])
		A = []
		B = []
	else:
		A.append(num_list[0])
		B.append(num_list[1])
		if len(A) == battle_num:
			battle_A_B(A,B)	

for i in range(len(insert_list)):
	print(insert_list[i])

Python: # AOJ 0500: Card Game
# Python3 2018.6.29 bal4u

while True:
	n = int(input())
	if n == 0: break
	sa = sb = 0
	for i in range(n):
		a, b = map(int, input().split())
		if a == b:
			sa += a
			sb += b
		elif a > b: sa += a+b
		else:       sb += a+b
	print(sa, sb)

Python: import sys

while True:
	num = int(input())
	if num == 0:
		break
	point = [0,0]
	for i in range(num):
		a, b = map(int, input().split())
		if a < b:
			point[1] += a+b
		elif b < a:
			point[0] += a+b
		else:
			point[0] += a
			point[1] += b

	print(point[0], point[1])

Python: fin_a = []
fin_b = []
while True:
    x = int(input())
    if x == 0:
        break
    a = 0
    b = 0
    for i in range(x):
        l = list(map(int, input().split()))
        if l[0] > l[1]:
            a += l[0] + l[1]
        elif l[0] < l[1]:
            b += l[0] + l[1]
        else:
            a += l[0]
            b += l[1]
    fin_a.append(a)
    fin_b.append(b)
    
for x, y in zip(fin_a, fin_b):
    print(x, y)

Python: n=int(input())
a_point=0
b_point=0
sum_list=[]
while(n!=0):
    list=[]
    for i in range(n):
        a,b=[int(i) for i in input().split()]
        if a>b:
            a_point+=(a+b)
        elif b>a:
            b_point+=(a+b)
        else:
            a_point+=a
            b_point+=b
    sum_list.append((a_point,b_point))
    a_point=0
    b_point=0
    n=int(input())

for i in range(len(sum_list)):
    print(sum_list[i][0],sum_list[i][1])

Python: while True:
    N = int(input())
    if N == 0:
        break

    # ??????????????????????¨???????????????°?????????
    (a, b) = (0, 0)
    
    inputs = []

    # ???????????°???????????????
    for x in range(N):
        # ??????????????????????????????
        inputs.append(list(map(int, input().split())))

    for points in inputs:
        # ?????°?????????????????????????????°???????¨?????????????
        if points[0] == points[1]:
            a = a + points[0]
            b = b + points[1]
        elif points[0] > points[1]:
            a = a + points[0] + points[1]
        else:
            b = b + points[0] + points[1]

    # ????????????????????¨???
    print(a,b)

Python: while(True):
  loopNum = int(input())
  if loopNum == 0 :
    break
  firstScore = 0
  secondScore = 0
  for i in range(loopNum):
    scoreList = list(map(int,input().split()))
    firstNum, secondNum = scoreList
    if firstNum > secondNum:
      firstScore += firstNum + secondNum
    elif firstNum < secondNum:
      secondScore += firstNum + secondNum  
    else :
      firstScore += firstNum
      secondScore += secondNum
  print(firstScore,secondScore)

Python: while 1:
    n = int(input())
    if n == 0:
        break
    
    sum_a = 0
    sum_b = 0
    
    for i in range(n):
        a,b = map(int, input().split())
        
        if a > b:
            sum_a = sum_a + a + b
        elif a < b:
            sum_b = sum_b + a + b
        elif a == b:
            sum_a = sum_a + a
            sum_b = sum_b + b

    print("%s %s" %(sum_a,sum_b))

Python: while True:
    n = int(input())
    if n == 0: break
    sa = sb = 0
    for i in range(n):
        a, b = map(int, input().split())
        if a == b:
            sa += a
            sb += b
        elif a > b: sa += a+b
        else:       sb += a+b
    print(sa, sb)

Python: # coding: utf-8
# Here your code !

i = int(input().rstrip())
point = []
k = 0
while i :
    point.append([0, 0])
    for j in range(i):
        l = list(map(int, input().rstrip().split()))
        if l[0] > l[1]:
            point[k][0] += l[0] + l[1]
        elif l[0] < l[1]:
            point[k][1] += l[0] + l[1]
        else:
            point[k][0] += l[0]
            point[k][1] += l[1]
    i = int(input().rstrip())
    k += 1
for i in range(k):
    print(point[i][0],point[i][1])

Python: while True:
    n = int(input())
    if n == 0:
        break
    score = [0, 0]
    for _ in range(n):
        A, B = map(int, input().split())
        if A == B:
            score += [A, B]
        else:
            score[A < B] += A+B
    print(*score)