import java.util.*; public class Main { static ArrayList> graph = new ArrayList<>(); static long ans = 0; static final int MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); TreeSet unused = new TreeSet<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); unused.add(i); } for (int i = 0; i < n - 1; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; graph.get(a).add(b); unused.remove(b); } calc(unused.first(), 0); System.out.println(ans); } static int calc(int idx, long depth) { int children = 1; for (int x : graph.get(idx)) { children += calc(x, depth + 1); } ans += children * depth % MOD; ans %= MOD; return children; } }