#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
long long w[100010],mk[1010][1010],res;
int n,f[100010],flag[100010];
int LCA (int x,int y) {
int cnt;
for (int i=x;i;i=f[i]) flag[i]=1;
for (int i=y;i;i=f[i]) {
if (flag[i]) {
cnt=i;
break;
}
}
for (int i=x;i;i=f[i]) flag[i]=0;
return cnt;
}
int main () {
freopen("asm_algo.in","r",stdin);
freopen("asm_algo.out","w",stdout);
cin >> n >> w[1];
for (int i=2;i<=n;i++) {
cin >> f[i] >> w[i];
}
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
if (mk[j][i]) {
res+=mk[j][i];
res%=mod;
continue;
}
mk[i][j]=w[i]*w[j]*w[LCA(i,j)];
mk[i][j]%=mod;
res+=mk[i][j];
res%=mod;
}
}
cout << res <<endl;
return 0;
}