n = int(eval(input()))

atob = []

ans = 0

for i in range(n):

    x,y = list(map(int,input().split()))

    ans += x

    atob.append(x+y)

    

atob.sort(reverse=True)



for i in range(n//2):

    ans -= atob[2*i+1]

    

print(ans)
n = int(eval(input()))

ans = 0

cou = []

for i in range(n):

    a , b = list(map(int,input().split()))

    ans += a

    cou.append(a+b)

cou.sort(reverse=True)

for i in range(1,n,2):

    ans -= cou[i]

print(ans)
n = int(eval(input()))
atob = []
ans = 0
for i in range(n):
    x, y = list(map(int, input().split()))
    ans += x
    atob.append(x + y)
atob.sort(reverse=True)
for i in range(n // 2):
    ans -= atob[2 * i + 1]
print(ans)

n = int(eval(input()))
ans = 0
cou = []
for i in range(n):
    a, b = list(map(int, input().split()))
    ans += a
    cou.append(a + b)
cou.sort(reverse=True)
for i in range(1, n, 2):
    ans -= cou[i]
print(ans)

-atob = [] +cou = [] -    x, y = list(map(int, input().split())) -    ans += x -    atob.append(x + y) -atob.sort(reverse=True) -for i in range(n // 2): -    ans -= atob[2 * i + 1] +    a, b = list(map(int, input().split())) +    ans += a +    cou.append(a + b) +cou.sort(reverse=True) +for i in range(1, n, 2): +    ans -= cou[i]