#include<cstdio>
#include<vector>
using namespace std;
vector<long long> v[100010];
long long w[100010]={0};
int main()
{
freopen("asm_algo.in","r",stdin);
freopen("asm_algo.out","w",stdout);
int n,fa;
scanf("%d%d",&n,&w[1]);
long long ans=0,sum=((w[1]*w[1])%1000000007)*w[1]%1000000007;
for (int i=2;i<=n;i++)
{
scanf("%d%d",&fa,&w[i]);
v[fa].push_back(i);
sum=(((w[i]*w[i])%1000000007)*w[i]+sum)%1000000007;
}
for (int i=1;i<=n;i++)
{
long long sum1=w[i],sum2=w[i]*w[i];
for (int j=0;j<v[i].size();j++)
{
sum1+=w[v[i][j]];
sum2=(sum2+w[v[i][j]]*w[v[i][j]])%1000000007;
}
sum1=((sum1 %1000000007)*(sum1 %1000000007))%1000000007;
ans=((sum1-sum2)%1000000007*w[i]+ans)%1000000007;
}
ans=(ans+sum)%1000000007;
printf("%d ",ans);
}