
object Main {
  def main(args: Array[String]) {
    val input = io.Source.stdin.getLines().mkString("\n");
    println(solve(input))

    def solve(input: String): String = {
      val nq :: list = input.split("\n").toList
      val (n, _) = spiltTwoInt(nq)
      val abs = list.take(n - 1).map(spiltTwoInt).sortBy(_._1)
      val qs = list.drop(n - 1).map(spiltTwoInt)

      val temp = qs.foldLeft(Vector.fill(n)(0)) {
        case (acc, (p, x)) =>
          val current = acc(p - 1)
          acc.updated(p - 1, x + current)
      }
      abs
        .foldLeft(temp) {
          case (acc, (a, b)) =>
            val curent = acc(b - 1)
            acc.updated(b - 1, curent + acc(a - 1))
        }
        .mkString(" ")
    }
  }

  def spiltTwoInt(s: String): (Int, Int) = {
    val res = s.split(" ").map(_.toInt)
    (res(0), res(1))
  }
}
