loop do
    n = gets.to_i
    break if n == 0
    name = Array.new(n)
    c = Array.new(n)
    n.times do |i|
        c[i] = gets.split
        c[i][1...c[i].size] = c[i][1...c[i].size].map(&:to_i)
    end
    c.each do |cc|
        t = cc[2] + cc[3] + cc[4] 
        t += (cc[5] + cc[6]) * cc[9]
        v = cc[7] * cc[8] * cc[9]
        cc[10] = (v.to_f - cc[1].to_f)/t.to_f
    end
    puts c.sort { |a, b| (b[10] <=> a[10]).nonzero? || a[0] <=> b[0] }.map{|a| a[0]}
    puts "\#"
end