#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    vector<pair<double,string> > crop;
    // -value,name
    REP(i,n){
      string name;
      double p,a,b,c,d,e,f,s,m;
      cin >> name >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      crop.push_back(make_pair(-(f*s*m-p)/(a+b+c+(d+e)*m),name));
    }
    SORT(crop);
    REP(i,crop.size()) cout << crop[i].second << endl;
    cout << '#' << endl;
  }
}