n = int(eval(input()))

ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort(reverse = True, key = lambda x:x[0]+x[1])

ans = 0

for i in range(n):

    ans += (1-i%2)*ab[i][0] - (i%2)*ab[i][1]

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

AB = [list(map(int, input().split())) for _ in range(n)]

AB.sort(key=lambda x: - x[0] - x[1])

print((sum([a[0] for a in AB[::2]]) - sum([a[1] for a in AB[1::2]])))
n = int(eval(input()))
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(reverse=True, key=lambda x: x[0] + x[1])
ans = 0
for i in range(n):
    ans += (1 - i % 2) * ab[i][0] - (i % 2) * ab[i][1]
print(ans)

n = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort(key=lambda x: -x[0] - x[1])
print((sum([a[0] for a in AB[::2]]) - sum([a[1] for a in AB[1::2]])))

-ab = [list(map(int, input().split())) for _ in range(n)] -ab.sort(reverse=True, key=lambda x: x[0] + x[1]) -ans = 0 -for i in range(n): -    ans += (1 - i % 2) * ab[i][0] - (i % 2) * ab[i][1] -print(ans) +AB = [list(map(int, input().split())) for _ in range(n)] +AB.sort(key=lambda x: -x[0] - x[1]) +print((sum([a[0] for a in AB[::2]]) - sum([a[1] for a in AB[1::2]])))