while true
    n = gets.to_i
    break if n == 0
    score = []
    n.times{|i|
        line = gets.chomp
        score << [line[0], line.count("0"), line.count("1"), i]
    }
    score.sort_by{|a, b, c, d| [-b, c, d]}.each{|a, b, c, d| puts a}
end
