### constant

MAX_D = 30

### main

loop do
  n = gets.to_i
  break if n == 0

  chrs = []
  diss = []
  dcounts = MAX_D.times.map{0}

  n.times do
    chr, m, *ds = gets.strip.split
    dis = ds.map{|d| d.to_i}

    chrs << [0, chr]
    diss << dis

    for d in dis
      dcounts[d] += 1
    end
  end
  #p dcounts

  for i in (0...n)
    for d in diss[i]
      chrs[i][0] += (n + 1 - dcounts[d])
    end
  end

  puts chrs.sort[0].join(' ')
end