import sys input = sys.stdin.buffer.readline from collections import deque N = int(input()) E = [[] for _ in range(N)] par = [-1]*N for _ in range(N-1): a,b = map(int, input().split()) E[a-1].append(b-1) par[b-1] = a-1 root = par.index(-1) ans = 0 mod = 10**9+7 q = deque() q.append(root) while q: temp = q.pop() p = temp%N rnk = temp//N ans += rnk*(rnk+1)//2 ans %= mod for v in E[p]: q.append((rnk+1)*N+v) print(ans)