N = int(eval(input()))

ABab = []

for i in range(N):

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

    ABab.append([a+b, a, -1*b])

ABab.sort(reverse = True)

ans = 0

for i in range(N):

    ans += ABab[i][i%2 + 1]

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

ABa = []

ans = 0

for i in range(N):

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

    ABa.append(a+b)

    ans -= b

ABa.sort(reverse = True)

for i in range(N):

    if i % 2 == 0:

        ans += ABa[i]

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

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

-ABab = [] +ABa = [] +ans = 0 -    ABab.append([a + b, a, -1 * b]) -ABab.sort(reverse=True) -ans = 0 +    ABa.append(a + b) +    ans -= b +ABa.sort(reverse=True) -    ans += ABab[i][i % 2 + 1] +    if i % 2 == 0: +        ans += ABa[i]