N = int(eval(input()))

E = [[] for _ in range(N)]

for _ in range(N - 1):

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

    E[v-1].append(u-1)

ans = 0

for u, adj in enumerate(E):

    ans += (u + 1) * (u + 2) // 2

    if not adj: continue

    adj = sorted(adj, reverse=True)

    for v in adj:

        ans -= (N - u) * (v + 1)

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

E = []

for _ in range(N - 1):

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

    E.append((u, v))

ans = 0

for v in range(1, N+1):

    ans += (N - v + 1) * v

for u, v in E:

    ans -= (N - v + 1) * u

print(ans)
N = int(eval(input()))
E = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v = sorted(list(map(int, input().split())))
    E[v - 1].append(u - 1)
ans = 0
for u, adj in enumerate(E):
    ans += (u + 1) * (u + 2) // 2
    if not adj:
        continue
    adj = sorted(adj, reverse=True)
    for v in adj:
        ans -= (N - u) * (v + 1)
print(ans)

N = int(eval(input()))
E = []
for _ in range(N - 1):
    u, v = sorted(list(map(int, input().split())))
    E.append((u, v))
ans = 0
for v in range(1, N + 1):
    ans += (N - v + 1) * v
for u, v in E:
    ans -= (N - v + 1) * u
print(ans)

-E = [[] for _ in range(N)] +E = [] -    E[v - 1].append(u - 1) +    E.append((u, v)) -for u, adj in enumerate(E): -    ans += (u + 1) * (u + 2) // 2 -    if not adj: -        continue -    adj = sorted(adj, reverse=True) -    for v in adj: -        ans -= (N - u) * (v + 1) +for v in range(1, N + 1): +    ans += (N - v + 1) * v +for u, v in E: +    ans -= (N - v + 1) * u