#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;

bool compare(const pair<string,double> &a,const pair<string,double> &b){
  if(a.second==b.second) return a.first<b.first;
  else return a.second>b.second;
}

int main(void){
  int n;
  while(cin>>n,n){
    vector<pair<string,double> > v;
    for(int i=0;i<n;++i){
      string l;
      int p,a,b,c,d,e,f,s,m;
      cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
      v.push_back(make_pair(l,(double)(f*s*m-p)/(a+b+c+(d+e)*m)));
    }
    sort(v.begin(),v.end(),compare);
    for(int i=0;i<v.size();++i){
      cout<<v[i].first<<endl;
    }
    cout<<"#"<<endl;
  }
}