MAX_COST = Float::INFINITY

def calc_min_costs_from(v_start, costs)
  vert_struct = Struct.new :id, :cost_from_start do
    define_method :cost_to do |v_to|
      costs[id][v_to.id]
    end

    def connected_to?(v_to)
      0 <= cost_to(v_to)
    end

    def cost_from_start_through(other_v)
      other_v.cost_from_start + other_v.cost_to(self)
    end
  end

  n_vertexes = costs.size
  verts = n_vertexes.times.map do |id|
    vert_struct.new(id, MAX_COST)
  end

  verts[v_start].cost_from_start = 0
  visiting = {}
  visiting[v_start] = verts[v_start]

  while visiting.any?
    v_from = visiting.min_by { |_, v| v.cost_from_start }[1]
    visiting.delete v_from.id

    verts.each do |v_to|
      next unless v_from != v_to && v_from.connected_to?(v_to)
      through_cost = v_to.cost_from_start_through v_from
      if through_cost < v_to.cost_from_start
        v_to.cost_from_start = through_cost
        visiting[v_to.id] = v_to
      end
    end
  end

  verts.map { |v| v.cost_from_start }
end

n_vertexes = gets.to_i
costs      = Array.new(n_vertexes) { Array.new(n_vertexes, -1) }
n_vertexes.times do
  v_from, n_degrees, *inputs = gets.split.map &:to_i
  1.step(n_degrees * 2, 2) do |i|
    v_to, cost = inputs[i - 1], inputs[i]
    costs[v_from][v_to] = cost
  end
end

min_costs = calc_min_costs_from(0, costs)
puts min_costs.map.with_index{ |cost, v| "#{v} #{cost}" }