n = int(input()) g = [[] for _ in range(n)] for i in range(n-1): a,b,c = [int(i) for i in input().split()] g[a-1].append((b-1,c)) g[b-1].append((a-1,c)) order = [] st = [0] parent = [-1]*n dist = [0]*n while st: v = st.pop() order.append(v) for c,wt in g[v]: if c != parent[v]: st.append(c) parent[c] = v dist[c] = wt sum1 = [0]*n sum2 = [0]*n cnt = [1]*n MOD = 10**9+7 ans = 0 for v in order[::-1]: if v==0: continue d = dist[v] sum2[v] += 2*d*sum1[v]+(d**2)%MOD*cnt[v] sum2[v] %= MOD sum1[v] += d*cnt[v] sum1[v] %= MOD p = parent[v] ans += cnt[p]*sum2[v] + cnt[v]*sum2[p] + 2*sum1[v]*sum1[p] ans %= MOD cnt[p] += cnt[v] sum1[p] += sum1[v] sum1[p] %= MOD sum2[p] += sum2[v] sum2[p] %= MOD print(ans)