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

object Main {
  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 mp = new HashMap[Int,Int]
    for(i<-0 until n) {
      dist(i) = 100000
      mp += (i->100000)
    }
    dist(0) = 0
    mp.update(0->0)

    while(!mp.isEmpty) {
      val minV = mp.minBy{ case (key,value) => value }
      val min = minV._2
      val v = g(minV._1)

      for(i<-0 until v(1)) {
        val j = i*2+2
        val k = i*2+3
        if(mp.contains(v(j))) {
          if(v(k)+dist(v(0)) < dist(v(j))) {
            dist(v(j)) = v(k) + dist(v(0))
            mp.update(v(j), v(k) + dist(v(0)))
          }
        }
      }
      visited += v(0)
      mp -= v(0)
    }

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