n = int(eval(input()))

ab = []

ans = 0

for i in range(n):

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

    ab.append([a+b,b])

    ans -= b

ab.sort(reverse=True)

for i in range(n):

    if i%2 == 0:

        ans += ab[i][0]

print(ans)

N = int(eval(input()))

AB = []

ans = 0

for i in range(N):

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

    ans += a

    AB.append(a+b)



AB.sort(reverse=True)

for i in range(N):

    if i%2 == 1:

        ans -= AB[i]



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

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

-n = int(eval(input())) -ab = [] +N = int(eval(input())) +AB = [] -for i in range(n): +for i in range(N): -    ab.append([a + b, b]) -    ans -= b -ab.sort(reverse=True) -for i in range(n): -    if i % 2 == 0: -        ans += ab[i][0] +    ans += a +    AB.append(a + b) +AB.sort(reverse=True) +for i in range(N): +    if i % 2 == 1: +        ans -= AB[i]