#include <iostream>
#include <algorithm>

using namespace std;

struct sPlant {
	string name;
	double sale;
};

bool Greater(const sPlant& lPlant, const sPlant& rPlant) {
	if( lPlant.sale != rPlant.sale) return lPlant.sale > rPlant.sale;
	return lPlant.name < rPlant.name;
}

int main()
{
	int n;
	while(cin >> n, n) {
		sPlant plants[51];
		for(int i = 0; i < n; ++i) {
			string name;
			int cost, a, b, c, d, e, num, price, rep;
			int plus, t;
			cin >> name >> cost >> a >> b >> c >> d >> e >> num >> price >> rep;
			t = a + b + c + (d + e) * rep;
			plus = price * num * rep - cost;
			plants[i].name = name;
			plants[i].sale = (double)plus / t;
		}
		sort(plants, plants + n, Greater);
		for(int i = 0; i < n; i++) {
			cout << plants[i].name << endl;
		}
		cout << '#' << endl;
	}
	return 0;
}