n = int(eval(input()))

seat = [0] * 10 ** 6

for i in range(n):

    l, r = list(map(int, input().split()))

    for j in range(l, r + 1):

        seat[j - 1] = 1



res = 0

for i in range(10 ** 6):

    if seat[i] == 1:

        res += 1

print(res)

n = int(eval(input()))

seat = [0] * (10 ** 5 + 1)

for i in range(n):

    l, r = list(map(int, input().split()))

    seat[l - 1] += 1

    seat[r] -= 1



for i in range(1, 10 ** 5):

    seat[i] += seat[i - 1]



res = 0

for i in range(10 ** 5):

    if seat[i] == 1:

        res += 1

print(res)

n = int(eval(input()))
seat = [0] * 10**6
for i in range(n):
    l, r = list(map(int, input().split()))
    for j in range(l, r + 1):
        seat[j - 1] = 1
res = 0
for i in range(10**6):
    if seat[i] == 1:
        res += 1
print(res)

n = int(eval(input()))
seat = [0] * (10**5 + 1)
for i in range(n):
    l, r = list(map(int, input().split()))
    seat[l - 1] += 1
    seat[r] -= 1
for i in range(1, 10**5):
    seat[i] += seat[i - 1]
res = 0
for i in range(10**5):
    if seat[i] == 1:
        res += 1
print(res)

-seat = [0] * 10**6 +seat = [0] * (10**5 + 1) -    for j in range(l, r + 1): -        seat[j - 1] = 1 +    seat[l - 1] += 1 +    seat[r] -= 1 +for i in range(1, 10**5): +    seat[i] += seat[i - 1] -for i in range(10**6): +for i in range(10**5):