import sys sys.setrecursionlimit(10**7) input=sys.stdin.readline n=int(input()) uvw=[list(map(int,input().split())) for _ in range(n-1)] ki=[[] for _ in range(n)] for u,v,w in uvw: u,v=u-1,v-1 ki[u].append([v,w]) ki[v].append([u,w]) mod=10**9+7 memo={} def dfs1(p,v):# numv,sumv=1,0 for nv,nw in ki[v]: if nv==p:continue num_,sum_=dfs1(v,nv) numv+=num_ sumv+=sum_+num_*nw sumv%=mod memo[(p,v)]=numv,sumv return numv,sumv dfs1(-1,0) ans=0 def dfs2(p,v): global ans snumv,ssumv=1,0 for nv,nw in ki[v]: num_,sum_=memo[(v,nv)] snumv+=num_ ssumv+=sum_+num_*nw ssumv%=mod for nv,nw in ki[v]: if nv==p:continue num0,sum0=memo[(v,nv)] num1,sum1=snumv-num0,ssumv-sum0-nw*num0 num1,sum1=num1%mod,sum1%mod tmp=num0*sum1+num1*sum0+nw*num0*num1 tmp*=nw tmp%=mod ans+=tmp ans%=mod memo[(nv,v)]=num1,sum1 dfs2(v,nv) dfs2(-1,0) print(ans)