#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;



int main() {
	while(1) {
		int N; cin >> N;
		if (!N)break;
		vector<pair<string, long double>>pls;
		for (int i = 0; i < N; ++i) {
			string st;
			int p, a, b, c, d, e, f, s, m; cin >> st>>p >> a >> b >> c >> d >> e >> f >> s >> m;
			int initime = a + b + c;
			int rooptime = d + e;
			int money = m*s*f-p;
			long double eff = static_cast<long double>(money) / static_cast<long double>(initime + rooptime*(m));
			pls.push_back(make_pair(st, eff));
		}
		sort(pls.begin(), pls.end(), [](const pair<string, long double>&l, const pair<string, long double>&r) {return abs(l.second-r.second)<1e-66?l.first<r.first:l.second > r.second; });
		for (int i = 0; i < pls.size(); ++i) {
			cout << pls[i].first << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}