N = int(eval(input()))

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



A = []

C = []

for a, b in AB:

  A.append(a)

  C.append(a + b)

#print("C:", C)



C.sort()

C = C[::-1]



print((sum(A) - sum(C[1::2])))
N = int(eval(input()))

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



A = [a for a, b in AB]

C = [a + b for a, b in AB]

C.sort()

C = C[::-1]

print((sum(A) - sum(C[1::2])))
N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(N)]
A = []
C = []
for a, b in AB:
    A.append(a)
    C.append(a + b)
# print("C:", C)
C.sort()
C = C[::-1]
print((sum(A) - sum(C[1::2])))

N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(N)]
A = [a for a, b in AB]
C = [a + b for a, b in AB]
C.sort()
C = C[::-1]
print((sum(A) - sum(C[1::2])))

-A = [] -C = [] -for a, b in AB: -    A.append(a) -    C.append(a + b) -# print("C:", C) +A = [a for a, b in AB] +C = [a + b for a, b in AB]