#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
using namespace std;

struct crop{
  double e;
  string name;
  crop(double e, string n) :e(e), name(n){}

  bool operator<(const crop& c) const {
    return e != c.e ? e > c.e : name < c.name;
  }
};

int main(){
  
  for(int n;cin>>n,n;){
    vector<crop> l;
    for(int i=0;i<n;i++){
      string str;
      int p,a,b,c,d,e,f,s,m;
      cin>>str>>p>>a>>b>>c>>d>>e>>f>>s>>m;
      int syuunyuu = s*f*m-p;
      l.push_back(crop(((double)syuunyuu)/((double)a+b+c+(d+e)*m), str));
    }
    //cout << kane[0].first << " " << kane[0].second << endl;

    sort(l.begin(), l.end());

    for(int i=0;i<(int)l.size();i++) cout << l[i].name << endl;

    cout << '#' << endl;
  }

  return 0;
}