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).nonzero? or (a.lose <=> b.lose).nonzero? or (a.num <=> b.num).nonzero?}
	list.each do |ele|
		puts ele.name
	end
end