Title: Card Game

Two players, A and B, use cards with numbers from 0 to 9 to play a game. Each player is given n cards, which they place face down in a row. They then take turns flipping over one card at a time from left to right. The player with the higher number on their card takes both cards, and the sum of the numbers on the two cards becomes their score. If the two revealed cards have the same number, it's a tie, and each player takes one card. The game ends when all cards are revealed.

The input consists of multiple datasets, each ending with n=0. The number of datasets does not exceed 5.

For each dataset, output the scores of players A and B on a single line.

Example:
Input
3
9 1
5 4
0 8
3
9 1
5 4
1 0
3
9 1
5 5
1 8
0

Output
19 8
20 0
15 14

# Buggy version:
while True:
    n = int(input())
    if n == 0:break
    sum_a = sum_b = 0
    for i in range(n):
        a,b = map(int, raw_input().split())
        if a > b:sum_a = sum_a + a + b
        elif a < b:sum_b = sum_b + a + b
        else:
            sum_a = sum_a + a
            sum_b = sum_b + b
    print(sum_a,sum_b)


# Fixed version:
while True:
    n = int(input())
    if n == 0: break
    sum_a = 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
        else:
            sum_a = sum_a + a
            sum_b = sum_b + b
    print(sum_a,sum_b)

# Buggy version:
while 1:
    n = 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))

        



# Fixed version:
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(sum_a,sum_b)

# Buggy version:
x = int(input())
score_A = 0
score_B = 0
ans = []
while x:
    for i in range(x):
        y = [int(i) for  i in input().split()]
        if y[0] > y[1]:
            score_A += sum(y)
        elif y[0] < y[1]:
            score_B += sum(y)
        else:
            score_A += y[0]
            score_B += y[1]
    ans.append([score_A,score_B])
    score_A = 0 ; score_B = 0
    x = int(input()
for i in ans:
    print(*i)


# Fixed version:
x = int(input())
score_A = 0
score_B = 0
ans = []
while x:
    for i in range(x):
        y = [int(i) for  i in input().split()]
        if y[0] > y[1]:
            score_A += sum(y)
        elif y[0] < y[1]:
            score_B += sum(y)
        else:
            score_A += y[0]
            score_B += y[1]
    ans.append([score_A,score_B])
    score_A = 0 ; score_B = 0
    x = int(input())
for i in ans:
    print(*i)

# Buggy version:
while 1:
    n=int(input())
    if n==0: break
    a=b=0
    while n:
        c,d=map(int,input().split())
        if c<b:b+=c+d
        elif c>d:a+=c+d
        else:
             a+=c
             b+=c
        n-=1
    print(a,b)

# Fixed version:
while 1:
    n=int(input())
    if n==0: break
    a=b=0
    while n:
        c,d=map(int,input().split())
        if c<d:b+=c+d
        elif c>d:a+=c+d
        else:
             a+=c
             b+=c
        n-=1
    print(a,b)

# Buggy version:
def _resulting(ab):
    a, b = 0, 0
    for itr in ab:
        if itr[0] > itr[1]:
            a = a + (itr[0] + itr[1])
        elif itr[0] < itr[1]:
            b = b + (itr[0] + itr[1])
        else:
            a = a + itr[0]
            b = b + itr[1]
    return a, b


if __name__ == '__main__':
    N = int(input())
    ab = []

    for itr in range(0, N):
        ab.append(list(map(int, input().split())))

    a, b = _resulting(ab)
    print(a, b)

# Fixed version:
def _resulting(ab):
    a, b = 0, 0
    for itr in ab:
        if itr[0] > itr[1]:
            a = a + (itr[0] + itr[1])
        elif itr[0] < itr[1]:
            b = b + (itr[0] + itr[1])
        else:
            a = a + itr[0]
            b = b + itr[1]
    return a, b


if __name__ == '__main__':
    while True:
        N = int(input())
        if N != 0:
            ab = []

            for itr in range(0, N):
                ab.append(list(map(int, input().split())))

            a, b = _resulting(ab)

            print(a, b)
        else:
            break

# Buggy version:
while True:
    n_line = input()
    if n_line == "0":
        break
    score_a, score_b = (0, 0)
    for i in range(int(n_line)):
        a, b = [int(x) for x in input().split(" ")]
        if a >= b:
            score_a += a
        if a <= b:
            score_b += b
    print("{} {}".format(score_a, score_b))

# Fixed version:
while True:
    n_line = input()
    if n_line == "0":
        break
    score_a, score_b = (0, 0)
    for i in range(int(n_line)):
        a, b = [int(x) for x in input().split(" ")]
        if a > b:
            score_a += a + b
        elif a < b:
            score_b += a + b
        else:
            score_a += a
            score_b += b
    print("{} {}".format(score_a, score_b))

# Buggy version:
A_cards, B_cards = [], []
A_result, B_result = 0, 0

while True:
    n = int(input())
    
    if n == 0:
        break

    for i in range(n):
        A, B = map(int, input().split())
        A_cards.append(A)
        B_cards.append(B)
        if A_cards[i] > B_cards[i]:
            A_result += A_cards[i] + B_cards[i]
        elif A_cards[i] < B_cards[i]:
            B_result += A_cards[i] + B_cards[i]
        else:
            A_result += A_cards[i]
            B_result += B_cards[i]
    print('{} {}'.format(A_result, B_result))

# Fixed version:
A_cards, B_cards = [], []
A_result, B_result = 0, 0

while True:
    n = int(input())
    
    if n == 0:
        break

    for i in range(n):
        A, B = map(int, input().split())
        A_cards.append(A)
        B_cards.append(B)
        if A_cards[i] > B_cards[i]:
            A_result += A_cards[i] + B_cards[i]
        elif A_cards[i] < B_cards[i]:
            B_result += A_cards[i] + B_cards[i]
        elif A_cards[i] == B_cards[i]:
            A_result += A_cards[i]
            B_result += B_cards[i]
    print('{} {}'.format(A_result, B_result))
    
    A_cards, B_cards = [], []
    A_result, B_result = 0, 0

# Buggy version:
while True:
    n = int(input())
    if n == 0:break
    sumA = sumB = 0
    for i in range(n):
        c = list(map(int,input().split()))
        if c[0]==c[1]:
            sumA = sumA+c[0]
            sumB = sumB+c[1]
        else:
            sumA = sumA + (c[0]+c[1] if c[0]>c[1] else 0)
            sumB = sumB + (c[0]+c[1] if c[1]>c[0] else 0)
    print(sumA, " " , sumB)

# Fixed version:
while True:
    n = int(input())
    if n == 0:break
    sumA = sumB = 0
    for i in range(n):
        c = list(map(int,input().split()))
        if c[0]==c[1]:
            sumA = sumA+c[0]
            sumB = sumB+c[1]
        else:
            sumA = sumA + (c[0]+c[1] if c[0]>c[1] else 0)
            sumB = sumB + (c[0]+c[1] if c[1]>c[0] else 0)
    print(sumA, sumB)

# Buggy version:
while True:
    n = int(input())
    if n == 0:
        break
    score = {"A": 0, "B": 0}
    for _ in range(n):
        A, B = map(int, input().split())
        if A > B:
            score["A"] += A
        elif A < B:
            score["B"] += B
        else:
            score["A"] += A
            score["B"] += B
    print(score["A"], score["B"])

# Fixed version:
while True:
    n = int(input())
    if n == 0:
        break
    score = {"A": 0, "B": 0}
    for _ in range(n):
        A, B = map(int, input().split())
        if A > B:
            score["A"] += A+B
        elif A < B:
            score["B"] += A+B
        else:
            score["A"] += A
            score["B"] += B
    print(score["A"], score["B"])

# Buggy version:
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)

# Fixed version:
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[0] += A
            score[1] += B
        else:
            score[A < B] += A+B
    print(*score)

# Buggy version:
while 1:
 a=b=0;n=int(input())
 if n==0:break
 for i in[0]*n:
  s,t=map(int,input().split())
  b+=s if s<t else a+=s
  a+=t if s>t else b+=t
 print(a,b)


# Fixed version:
while 1:
 a=b=0;n=int(input())
 if n==0:break
 for i in[0]*n:
  s,t=map(int,input().split())
  if s>t:a+=s+t
  if s<t:b+=s+t
  if s==t:a+=s;b+=t
 print(a,b)

# Buggy version:
import sys
e=iter(sys.stdin)
while 1:
 a=b=0;n=int(e)
 if n==0:break
 for i in[0]*n:
  s,t=map(int,e.split())
  if s>t:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 print(a,b)


# Fixed version:
import sys
e=sys.stdin
while 1:
 a=b=0;n=int(e.readline())
 if n==0:break
 for i in[0]*n:
  s,t=map(int,e.readline().split())
  if s>t:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 print(a,b)

# Buggy version:
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)



# Fixed version:
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)

# Buggy version:
n = int(input())
while n != 0:
 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("{0} {1}".format(A, B))
  n = int(input())

# Fixed version:
n = int(input())
while (n != 0):
    A=0
    B=0
    for i in range(n):
        a,b = map(int, input().split())
        if (a>b):
            A+=(a+b)
        elif (b>a):
            B += (a+b)
        else:
            A+=a
            B+=b
    print("{} {}".format(A,B))
    n = int(input())