var f,w,d:array[1..100000] of longint;
n,i,j:longint;s:int64;
function lca(a,b:longint):longint;
var i:longint;
begin
if a=b then exit(a);
if d[a]>d[b] then
begin
for i:=1 to d[a]-d[b] do
a:=f[a];
end;
if d[b]>d[a] then
begin
for i:=1 to d[b]-d[a] do
b:=f[b];
end;
if a=b then exit(a);
exit(lca(f[a],f[b]));
end;
begin
assign(input,'asm_algo.in');
reset(input);
assign(output,'asm_algo.out');
rewrite(output);
readln(n,w[1]);
for i:=2 to n do
readln(f[i],w[i]);
f[1]:=1;
d[1]:=1;
for i:=1 to n-1 do
for j:=2 to n do
if f[j]=i then d[j]:=d[i]+1;
s:=0;
for i:=1 to n do
for j:=1 to n do
begin
s:=s+w[i]*w[j]*w[lca(i,j)];
if s>1000000007 then s:=s mod 1000000007;
end;
writeln(s);
close(input);
close(output);
end.