while (n = gets.chomp.to_i) != 0
  moments = Array.new(32){[]}

  n.times do
    line = gets.split

    line[2..-1].each{ |t| moments[t.to_i] << line[0] }
  end

  scores = {}
  moments.each do |t|
    p = n - t.size + 1
    t.each{ |name| scores[name] = (scores[name] ? scores[name]+p : p) }
  end

  puts scores.to_a.map(&:reverse).min.join(" ")
end