#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>

using namespace std;

typedef pair <double, string> P;

int main(void)
{
	int n;
	while (cin >> n, n){
		int p, a, b, c, d, e, f, s, m;
		string l;
		vector <P> ret;
		for (int i = 0; i < n; i++){
			cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			double per = (double)(f * s * m - p) / (a + b + c + ((d + e) * m));
			ret.push_back(make_pair(-per, l));
		}
		sort(ret.rbegin(), ret.rend());
		for (int i = n-1; 0 <= i; i--){
			cout << ret[i].second << endl;
		}
		puts("#");
	}

	return 0;
}