#include <bits/stdc++.h>
using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    vector<pair<LD,string>> v(n);
    string l;
    LD p,a,b,c,d,e,f,s,m;
    for(int i=0;i<n;i++){
      cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      v[i]={-(f*s*m-p)/(a+b+c+(d+e)*m),l};
    }
    sort(all(v));
    for(int i=0;i<n;i++){
      cout << v[i].second << endl;
    }
    cout << "#" << endl;
  }
  return 0;
}

