#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

int INF = 1<<20;
int main() {
	int n;
	while(cin >> n && n){
		map<string, double> sd;
		vector<string> svec;
		string str;
		int p, a, b, c, d, e, f, s, m;
		for(int i = 0; i < n; ++i){
			cin >> str >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			svec.push_back(str);
			int t = a + b + c + (d + e) * m;
			sd[str] = (double)(s * f * m - p) / t;
		}
		sort(svec.begin(), svec.end());
		double max_bf = -INF;
		string max_str;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				if(max_bf < sd[svec[j]]){
					max_bf = sd[svec[j]];
					max_str = svec[j];
				}
			}
			cout << max_str << endl;
			max_bf = -INF;
			sd[max_str] = -INF;
		}
		cout << "#" << endl;
	}
	return 0;
}