import Data.List
import Data.Ord

main = interact $ unlines . map (show' . moonlight_farm) . read' . lines
 where
  read' ("0":_) = []
  read' (n:xs) = map ((\(name:dat) -> (name, map read dat)) . words) xs1 : read' xs2
   where (xs1,xs2) = splitAt (read n) xs
  show' = (++ "#") . unlines

moonlight_farm = map fst . sortBy (comparing (negate.efficiency)) . sortBy (comparing fst)
efficiency (_,[p,a,b,c,d,e,f,s,m]) = (fromIntegral (f*s*m-p)) / (fromIntegral (a+b+c+m*(d+e)))