def calc(vertices)
  result = Hash.new(-1)
  result[0] = 0
  queue = [0] 
  
  until queue.empty? do
    current = queue.shift

    vertices[current].each do |neighbor|
      target = neighbor[0]
      length = neighbor[1]
      if (result[target] > 0) then
        if (result[current] > result[target] + length) then
          result[current] = result[target] + length
        end
      end
    end

    vertices[current].each do |neighbor|
      target = neighbor[0]
      length = neighbor[1]
      if (result[target] < 0) then
        result[target] = result[current] + length
        queue.push(target)
      else
        cand_route_len = result[current] + length
        result[target] = cand_route_len if cand_route_len < result[target]
      end
    end
  end

  return result 
end


# main
n = gets.chomp.to_i
vertices = {}
n.times do
  inputs = gets.chomp.split.map(&:to_i)
  neighbors = []
  2.step(2+inputs[1]*2-1, 2) do |i|
    neighbors << [inputs[i], inputs[i+1]]
  end
  vertices[inputs[0]] = neighbors
end

result = calc(vertices)
result.sort_by{|key, value| key}.each do |key, value|
  puts "#{key} #{value}"
end