loop do
  n = gets.to_i
  break if n==0
  hash = Hash.new
  names = Array.new
  n.times do
    name,*points = gets.chomp.split
    points.map!(&:to_i)
    w=0
    l=0
    points.each do |x|
      w+=1 if x==0
      l+=1 if x==1
    end
    hash[name]=[w,l]
    names << name
  end
  ans = names.sort do |a,b|
    if hash[a][0] != hash[b][0]
      hash[b][0]-hash[a][0]
    else hash[a][1] - hash[b][1]
    end
  end
  puts ans
end