N=int(input()) M=10**9+7 ans=0 G=[[(0,0)]*0 for i in range(N)] order=[0] sub_size=[0]*N pare=[(-1,0)]*N lower_sum=[0]*N upper_sum=[0]*N for i in range(N-1): a,b,c=map(int,input().split()) a-=1 b-=1 G[a].append((b,c)) G[b].append((a,c)) for i in range(N): a=order[i] for x in G[a]: if pare[a][0]!=x[0]: order.append(x[0]) pare[x[0]]=(a,x[1]) for i in range(N): a=order[N-1-i] L=pare[a][1] for x in G[a]: if x[0]!=pare[a][0]: sub_size[a]+=sub_size[x[0]] lower_sum[a]+=lower_sum[x[0]] lower_sum[a]%=M sub_size[a]+=1 ans+=(((sub_size[a]*(N-sub_size[a]))%M)*pow(L,2,M))%M ans+=(L*lower_sum[a]*(N-sub_size[a]))%M ans%=M lower_sum[a]+=L*sub_size[a] for i in range(N): a=order[i] L=pare[a][1] lower_sum[a]-=(L*sub_size[a])%M for x in G[a]: if pare[a][0]==x[0]: continue tmp=(upper_sum[a]+lower_sum[a]-lower_sum[x[0]])%M ans+=(x[1]*tmp*sub_size[x[0]])%M upper_sum[x[0]]=(tmp+x[1]*(N-sub_size[x[0]]))%M ans%=M print(ans)