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
  i=0
  ans = names.sort_by{|v|
    [-hash[v][0],i+=1]
  }
  ans = ans.sort_by{|v|
    [hash[v][1],i+=1]
  }
  puts ans
end