#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<double, string>P;

int main() {
	int n;
	while (scanf("%d", &n), n) {
		scanf("%d", &n);
		vector<P>v;
		rep(i, n) {
			string l;
			int p, a, b, c, d, e, f, s, m;
			cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			int time = a + b + c + (d + e)*m;
			int shu = f*m*s - p;
			v.push_back({ (double)shu / (double)time,l });
		}
		sort(v.begin(), v.end(), [](P a, P b) {
			if (a.first == b.first) {
				transform(a.second.begin(), a.second.end(), a.second.begin(), ::tolower);
				return a.second < b.second;
			}
			return a.first > b.first;
		});
		rep(i, n) {
			cout << v[i].second << endl;
		}
		cout << "#" << endl;
	}
}