loop do
    n = gets.to_i
    break if n == 0
    h = {}
    n.times do
        name, _, *scenes = gets.chomp.split
        scenes.each do |c|
            (h[c] ||= []) << name
        end
    end
    point = Hash.new(0)
    h.each do |_, names|
        names.each do |name|
            point[name] += n - names.size + 1
        end
    end
    puts point.min_by {|name, k| [k, name]}.reverse * ' '
end
