#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

typedef pair<double, string> P;
typedef pair<string, double> Q;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		string plant;
		int p, a, b, c, d, e, f, s, m;
		int time;
		double kou;
		priority_queue<P> pq;
		for (int i = 0; i < n; i++) {
			cin >> plant >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			time = a+b+c+(d+e)*m;
			kou = (double)(s*f*m-p) / (double)time;
			P pp;
			pp.first = kou;
			pp.second = plant;
			pq.push(pp);
		}
		while (!pq.empty()) {
			P ppp = pq.top();
			pq.pop();
			priority_queue< Q, vector<Q>, greater<Q> > pqq;
			Q q;
			q.first = ppp.second;
			q.second = ppp.first;
			pqq.push(q);
			while (!pq.empty()) {
				if ((pq.top()).first == ppp.first) {
					q.first = (pq.top()).second;
					pqq.push(q);
					pq.pop();
				} else {
					break;
				}
			}
			while (!pqq.empty()) {
				cout << (pqq.top()).first << endl;
				pqq.pop();
			}
		}
		cout << '#' << endl;
	}
	return 0;
}
#include<bits/stdc++.h>
using namespace std;

int N;
const double EPS = 1e-10;

struct state{
  string name;
  double k;
  state(){}
  state(int P,int A,int B,int C,int D, int E,int F,int S,int M){
    int time = A + B + C + (D + E)*M;
    int num = M * F;
    int mon = num * S;
    int s = mon - P;
    k = (double)s/(double)time;
  }
  bool operator<(const state& st) const {
    return abs(k-st.k) < EPS ? name < st.name : k > st.k;
  }
};

state st[111];
int main(){
  while( cin >> N && N ){
    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;
      st[i] = state(P,A,B,C,D,E,F,S,M);
      st[i].name = L;
   
    }
    sort(st,st+N);
    for(int i=0;i<N;i++)
      cout << st[i].name << endl;
    cout << "#" << endl;
  }
}