n = int(eval(input()))

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

ab.sort(key=lambda x: sum(x), reverse=True)

s = sum(a for a, _ in ab)

s -= sum(sum(dish) for dish in ab[1::2])

print(s)

n = int(eval(input()))



e = []

curr = 0

for _ in range(n):

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

    e.append(a + b)

    curr -= b



e.sort(reverse=True)

print((curr + sum(e[::2])))

n = int(eval(input()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: sum(x), reverse=True)
s = sum(a for a, _ in ab)
s -= sum(sum(dish) for dish in ab[1::2])
print(s)

n = int(eval(input()))
e = []
curr = 0
for _ in range(n):
    a, b = list(map(int, input().split()))
    e.append(a + b)
    curr -= b
e.sort(reverse=True)
print((curr + sum(e[::2])))

-ab = [tuple(map(int, input().split())) for _ in range(n)] -ab.sort(key=lambda x: sum(x), reverse=True) -s = sum(a for a, _ in ab) -s -= sum(sum(dish) for dish in ab[1::2]) -print(s) +e = [] +curr = 0 +for _ in range(n): +    a, b = list(map(int, input().split())) +    e.append(a + b) +    curr -= b +e.sort(reverse=True) +print((curr + sum(e[::2])))