
def min_graph(graph)
  10.times do |k|
    10.times do |i|
      10.times do |j|
        graph[i][j] = [graph[i][j], graph[i][k] + graph[k][j]].min
      end
    end
  end
end

def solve(graph)
  min_graph(graph)
  min = INF
  index = -1
  (0...10).each do |i|
    res = (0...10).map do |j|
      graph[i][j] == INF ? 0 : graph[i][j]
    end.reduce(&:+)
    if res != 0 and res < min
      min = res
      index = i
    end
  end
  [index, min]
end

INF = 1 << 31

loop do
  n = gets.to_i
  break if n == 0
  graph = Array.new(10).map {Array.new(10, INF)}
  n.times do
    from, to, cost = gets.split(" ").map(&:to_i)
    graph[from][to] = cost
    graph[to][from] = cost
    graph[from][from] = 0
    graph[to][to] = 0
  end
  i, dist = solve(graph)
  puts "#{i} #{dist}"
end