function count_up() {
  local x=$1
  local p=$2
  counts[$p]=$((counts[$p]+x))
  for _p in ${trees[$p]}
  do
    count_up $x $_p
  done
}

read N Q

while ((${i:=1} < N))
do
  counts[i]=0
  read a b
  trees[$a]="$b ${trees[$a]}"
  ((i++))
done

while read p x
do
  count_up $x $p
done <<EOF
  `cat -`
EOF

echo ${counts[*]}