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) def dfs2(p,v): snumv,ssumv=1,0 for nv,nw in ki[v]: num_,sum_=memo[(v,nv)] snumv+=num_ ssumv+=sum_+num_*nw ssumv%=mod ret=0 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 ret+=tmp ret%=mod memo[(nv,v)]=num1,sum1 ret+=dfs2(v,nv) ret%=mod return ret print(dfs2(-1,0))