class Team
  attr_accessor :name, :w, :l, :i
  def initialize(name, w, l, i)
    @name = name; @w = w; @l = l; @i =i;
  end
  def <=>(other)
    return other.w <=> @w if @w != other.w
    return @l <=> other.l if @l != other.l
    return @i <=> other.i if @i != other.i
  end
end

while n = gets.chomp.to_i and n != 0
  teams = []

  n.times do |i|
    inputs = gets.split
    name = inputs[0]
    w = inputs[1..n].count('0')
    l = inputs[1..n].count('1')

    teams << Team.new(name, w, l, i)
  end

  teams.sort.each{ |team| puts team.name }
end

  
    