def f(cost, a, b, c, d, e, f, s, m)
    time = a + b + c + (d + e) * m 
    sale = f * s * m 
    (sale - cost) / time
end

loop {
    n = gets.to_i
    break if n == 0
    a = (1..n).map {
        name, *params = gets.split
        [- f(*params.map(&:to_i)), name]
    }   
    puts a.sort.map(&:last)
    puts ?#
}