#include <cstdio>
#include <vector>
using namespace std;
#define NMAX 100000
#define P 1000000007
vector<int> g[NMAX+1];
long long w[NMAX+1],sum[NMAX+1];
long long dfs(int ind){
long long ans=0,s,tmp=0;
int tn;
int i;
s=w[ind];
for(i=0;i<g[ind].size();i++){
tn=g[ind][i];
ans=(ans+dfs(tn))%P;
tmp=(tmp+(s*sum[tn])%P)%P;
s=(s+sum[tn])%P;
}
tmp=((tmp*2)%P+(w[ind]*w[ind])%P)%P;
sum[ind]=s;
// printf("%lld\n",sum[ind]);
return ans=(ans+(tmp*w[ind])%P)%P;
}
int main(){
int n;
int tp;
int i;
freopen("asm_algo.in","r",stdin);
freopen("asm_algo.out","w",stdout);
scanf("%d%lld",&n,w+1);
for(i=2;i<=n;i++){
scanf("%d%lld",&tp,w+i);
g[tp].push_back(i);
}
printf("%lld",dfs(1));
return 0;
}