while gets
    n=$_.to_i
    names=Array.new
    teams=Hash.new
    break if n==0
    n.times do
        name,*team=gets.chomp.split(nil)
        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
    puts names.sort_by{|name|teams[name]}
end