#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int maxn=100000+10;
vector<int>A[maxn];
long long w[maxn];
long long summ[maxn];
const int MOD=1000000007;
long long ans=0;
inline void dfs(int x){
for(int i=0;i<A[x].size();i++){
int u=A[x][i];
dfs(u);
summ[x]+=summ[u];
summ[x]%=MOD;
}
for(int i=0;i<A[x].size();i++){
int u=A[x][i];
long long ls=(summ[x]-summ[u]+MOD)%MOD;
ans+=ls*summ[u]%MOD*w[x]%MOD;
}
long long ls=w[x]*summ[x]%MOD*w[x]%MOD;
ls%=MOD;
ls*=2;
ls%=MOD;
ans+=ls;
ans%=MOD;
summ[x]+=w[x];
summ[x]%=MOD;
ans+=w[x]*w[x]%MOD*w[x]%MOD;
}
int main(){
freopen("asm_algo.in","r",stdin);
freopen("asm_algo.out","w",stdout);
int n;
scanf("%d %d",&n,&w[1]);
w[1]%=MOD;
int x;
for(int i=2;i<=n;i++){
scanf("%d %d",&x,&w[i]);
w[i]%=MOD;
A[x].push_back(i);
}
dfs(1);
printf("%I64d\n",ans%MOD);
return 0;
}