class Graph
  attr_accessor :node
  def initialize(n=nil)
    @node = Array.new(n){Node.new}
  end
  def print
    @node.size.times{|i|
      puts "#{i} #{node[i].cost}"
    }
  end
end

class Node
  attr_accessor :edges_to, :edges_cost, :done, :cost
  def initialize
    @edges_to = []
    @edges_cost = []
    @done = false
    @cost = -1
  end
end

n = gets.to_i
graph = Graph.new(n)

n.times{
  u, k, *vc = gets.split.map(&:to_i)
  k.times{|i|
    graph.node[u].edges_to << vc[2*i]
    graph.node[u].edges_cost << vc[2*i+1]
  }
}

graph.node[0].cost = 0

loop do
  doneNode = nil
  n.times{|i|
    next if graph.node[i].done || graph.node[i].cost < 0
    doneNode = graph.node[i] if doneNode == nil || graph.node[i].cost < doneNode.cost
  }
  break if doneNode == nil

  doneNode.done = true
  doneNode.edges_to.size.times{|i|
    to = doneNode.edges_to[i]
    cost = doneNode.cost + doneNode.edges_cost[i]
    graph.node[to].cost = cost if graph.node[to].cost < 0 || cost < graph.node[to].cost
  }
end

graph.print