MOD = 10 ** 9 + 7 N = int(input()) E = [[] for _ in range(N)] D = [0] * N for _ in range(N - 1): a, b = map(int, input().split()) a -= 1 b -= 1 E[a].append(b) D[b] += 1 ans = 0 Q = [D.index(0)] Q2 = [] ans = 0 cnt = 0 cnt2 = 0 while Q: cnt2 += cnt cnt += 1 ans += cnt2 * len(Q) ans %= MOD while Q: x = Q.pop() for y in E[x]: Q2.append(y) Q, Q2 = Q2, Q print(ans)