while gets
    n = $_.to_i
    break if n==0
    teams = Hash.new
    names = Array.new
    n.times do
        name,*team = gets.chomp.split
        team.map!(&:to_i)
        w=0
        d=0
        (n-1).times do |i|
            w+=1 if team[i]==0
            d+=1 if team[i]==2
        end
        teams[name]=w*3+d
        names << name
    end
    i=0
    ans=names.sort_by do |x|
        [-teams[x],i+=1]
    end
    puts ans
end