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
    d=0
    points.each do |x|
      w+=1 if x==0
      d+=1 if x==2
    end
    hash[name]=w*n+d
    names << name
  end
  i=0
  ans = names.sort_by do |x|
    [-hash[x],i+=1]
  end
  puts ans
end