until (num = gets.chomp.to_i) == 0 
list = Array.new
decision = Struct.new(:name,:win,:lose,:num)
num.times do |i|
temp = gets.chomp.split
list[i] = decision.new(temp[0],temp.count("0"),temp.count("1"),i)
end
list.sort!{|a,b| b.win <=> a.win && a.lose <=> b.lose || a.num <=> b.num}
list.each do |ele|
puts ele.name
end
end