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

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]
    for(i<-0 until n) dist(i) = Int.MaxValue
    dist(0) = 0

    while(visited.length < n) {
      val minV = (for(i<-0 until dist.length if !visited.contains(i)) yield (dist(i),i)).min
      val min = minV._1
      val v = g(minV._2)

      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))
        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))
      }
      visited += v(0)
    }
    for(i<-0 until n) {
      println(i + " " + dist(i))
    }
  }
}