import scala.annotation.tailrec
import scala.io.StdIn._
object Main extends App {
  solve()
  @tailrec def solve(): Unit = {
    val n = readInt()
    if (n == 0) return
    val plants = Array.tabulate(n){_ ⇒
      val (Array(l), Array(p, a, b, c, d, e, f, s, m)) = readLine.trim.split(' ').splitAt(1) match {case (p, q) ⇒ (p, q.map(_.toInt))}
      Plant(l, p, a, b, c, d, e, f, s, m)
    }
    println(plants.sortWith{case (p, q) ⇒ if (p.efficient == q.efficient) p.name < q.name else p.efficient > q.efficient}.map{_.name}.mkString("", "\n", "\n#"))
    solve()
  }
  case class Plant(name: String, price: Int, bud: Int, youngLeaf: Int, leaf: Int, flower: Int, fruit: Int, fruitCount: Int, fruitPrice: Int, time: Int) {
    def wholeCycle: Int = bud + youngLeaf + leaf + (flower + fruit) * time
    def wholeBenefit: Int = time * fruitCount * fruitPrice - price
    def efficient: Double = (wholeBenefit / gcd(wholeCycle, wholeBenefit)).toDouble / (wholeCycle / gcd(wholeCycle, wholeBenefit))
  }
  def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
}
