
loop do
    n = gets.to_i
    break if n == 0
    qu = []
    n.times do
        line = gets.chomp.split
        l = line.shift
        pr,a,b,c,d,e,f,s,m = line.map(&:to_i)
        be = m*s*f-pr
        tm = a+b+c+(d+e)*m
        qu << [-Rational(be,tm),l]
    end
    qu.sort!.each do |r,l|
        puts l
    end
    puts '#'
end

