import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.HashMap

object Main {
  class Node(id:Int,dist:Int) { }

  def main(args:Array[String]) = {
    val n = readInt
    val g = for(i<-0 until n) yield { readLine.trim.split(" ").map(_.toInt) }
    val dist = new Array[Int](n)
    val visited = new ArrayBuffer[Int]
    val mp = new HashMap[Int,Int]
    for(i<-0 until n) dist(i) = Int.MaxValue
    dist(0) = 0
    mp += (0->0)

    while(visited.length < n) {
      val minV = mp.filter{ case (key,value) => !visited.contains(key) }.minBy{ case (key,value) => value }
      val min = minV._2
      val v = g(minV._1)

      for(i<-0 until v(1) if !visited.contains(v(i*2+2))) {
        if(dist(v(i*2+2)) == Int.MaxValue) {
          dist(v(i*2+2)) = v(i*2+3) + dist(v(0))
          mp += (v(i*2+2) -> (v(i*2+3) + dist(0)))
        } else if(v(i*2+3)+dist(v(0)) < dist(v(i*2+2))) {
          dist(v(i*2+2)) = v(i*2+3) + dist(v(0))
          mp.update(v(i*2+2), v(i*2+3) + dist(v(0)))
        }
      }
      visited += v(0)
      mp -= v(0)
    }

    for(i<-0 until n) {
      println(i + " " + dist(i))
    }
  }
}