n=int(eval(input()))

l=[[i]+list(map(int,input().split())) for i in range(n)]



l.sort(key=lambda x:-(x[1]+x[2]))

pa,pb=0,0

used=set()



v=0

while pa<n and pb<n:

  while pa<n and l[pa][0] in used:

    pa+=1

  if pa<n:

    used.add(l[pa][0])

    v+=l[pa][1]

  while pb<n and l[pb][0] in used:

    pb+=1

  if pb<n:

    used.add(l[pb][0])

    v-=l[pb][2]



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

l = []

for _ in range(N):

    A, B = list(map(int, input().split()))

    l.append((-abs(A+B), -A, -B))

l.sort()

a, b = 0, 0

for i in range(N):

    if i%2:

        b -= l[i][2]

    else:

        a -= l[i][1]



print((a-b))

n = int(eval(input()))
l = [[i] + list(map(int, input().split())) for i in range(n)]
l.sort(key=lambda x: -(x[1] + x[2]))
pa, pb = 0, 0
used = set()
v = 0
while pa < n and pb < n:
    while pa < n and l[pa][0] in used:
        pa += 1
    if pa < n:
        used.add(l[pa][0])
        v += l[pa][1]
    while pb < n and l[pb][0] in used:
        pb += 1
    if pb < n:
        used.add(l[pb][0])
        v -= l[pb][2]
print(v)

N = int(eval(input()))
l = []
for _ in range(N):
    A, B = list(map(int, input().split()))
    l.append((-abs(A + B), -A, -B))
l.sort()
a, b = 0, 0
for i in range(N):
    if i % 2:
        b -= l[i][2]
    else:
        a -= l[i][1]
print((a - b))

-n = int(eval(input())) -l = [[i] + list(map(int, input().split())) for i in range(n)] -l.sort(key=lambda x: -(x[1] + x[2])) -pa, pb = 0, 0 -used = set() -v = 0 -while pa < n and pb < n: -    while pa < n and l[pa][0] in used: -        pa += 1 -    if pa < n: -        used.add(l[pa][0]) -        v += l[pa][1] -    while pb < n and l[pb][0] in used: -        pb += 1 -    if pb < n: -        used.add(l[pb][0]) -        v -= l[pb][2] -print(v) +N = int(eval(input())) +l = [] +for _ in range(N): +    A, B = list(map(int, input().split())) +    l.append((-abs(A + B), -A, -B)) +l.sort() +a, b = 0, 0 +for i in range(N): +    if i % 2: +        b -= l[i][2] +    else: +        a -= l[i][1] +print((a - b))