n = int(eval(input()))

V = E = 0

for d in range(1,n+1): V += d * (d + 1) // 2

for _ in range(n-1):

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

    if a > b: a, b = b, a

    E += a * (n - b + 1)

print((V - E))

n = int(eval(input()))

V = n*(n+1)*(n+2)//6; E = 0

for _ in range(n-1):

    u, v = list(map(int, input().split()))

    if u > v: u, v = v, u

    E += u * (n - v + 1)

print((V - E))

n = int(eval(input()))
V = E = 0
for d in range(1, n + 1):
    V += d * (d + 1) // 2
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    if a > b:
        a, b = b, a
    E += a * (n - b + 1)
print((V - E))

n = int(eval(input()))
V = n * (n + 1) * (n + 2) // 6
E = 0
for _ in range(n - 1):
    u, v = list(map(int, input().split()))
    if u > v:
        u, v = v, u
    E += u * (n - v + 1)
print((V - E))

-V = E = 0 -for d in range(1, n + 1): -    V += d * (d + 1) // 2 +V = n * (n + 1) * (n + 2) // 6 +E = 0 -    a, b = list(map(int, input().split())) -    if a > b: -        a, b = b, a -    E += a * (n - b + 1) +    u, v = list(map(int, input().split())) +    if u > v: +        u, v = v, u +    E += u * (n - v + 1)