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 = Hash.new(0)
  moments.each do |names|
    p = n - names.size + 1
    names.each{ |name| scores[name] += p }
  end

  ans = scores.to_a.map(&:reverse).min
  puts ans[0].to_s + " " + ans[1]
end