import java.util.*; import java.io.*; public class Main { static ArrayList> graph = new ArrayList<>(); static int[] children; static int[] depth; static final int MOD = 1000000007; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] aArr = new int[n - 1]; int[] bArr = new int[n - 1]; children = new int[n]; depth = new int[n]; int[] counts = new int[n]; for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < n - 1; i++) { String[] line = br.readLine().split(" ", 2); aArr[i] = Integer.parseInt(line[0]) - 1; bArr[i] = Integer.parseInt(line[1]) - 1; graph.get(aArr[i]).add(bArr[i]); counts[bArr[i]]++; } int root = 0; for (int i = 0; i < n; i++) { if (counts[i] == 0) { root = i; break; } } getChildren(root, 1); long ans = 0; for (int i = 0; i < n - 1; i++) { ans += (long)(depth[aArr[i]]) * children[bArr[i]] % MOD; ans %= MOD; } System.out.println(ans); } static int getChildren(int idx, int d) { children[idx] = 1; depth[idx] = d; for (int x : graph.get(idx)) { children[idx] += getChildren(x, d + 1); } return children[idx]; } }