#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

#define NMAX 50

int N;
string L;
int P;
int A;
int B;
int C;
int D;
int E;
int F;
int S;
int M;

typedef pair<double,string> sd;

vector<pair<double,string> > Q; 

int main()
{
    int T;
    int I;
    double r;
    while(cin >> N){
        if(N == 0)break;
        REP(N){
            cin >>L>>P>>A>>B>>C>>D>>E>>F>>S>>M;
            T = A+B+C+M*(D+E);
            I = M*S*F-P;
            T = T;
            r = (double)I/(double)T; 
            Q.push_back(sd(-1.0*r,L));         
        }
        sort(all(Q));
        REP(Q.size()){
            cout << Q[i].second <<endl;
        }
        Q.clear();
        cout << "#" << endl;
    }
    return 0;
}