#include <bits/stdc++.h>
using namespace std;

typedef pair<double, string> P;

void solve(int n){
	vector<P> v;
	for(int i=0; i<n; ++i){
		string s;
		cin >> s;
		int a[9];
		for(int j=0; j<9; ++j)
			cin >> a[j];
		int b = a[8] * a[7] * a[6] - a[0];
		int c = a[1] + a[2] + a[3] + a[8] * (a[4] + a[5]);
		double d = 0.0;
		if(b == 0) d = 1e9;
		else d = -(double)b/c;
		v.push_back(P(d, s));
	}
	sort(v.begin(), v.end());
	for(int i=0; i<n; ++i){
		cout << v[i].second << "\n";
//		cout << v[i].first << "\n";
	}
	cout << "#\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n;
		cin >> n;
		if(n == 0) return 0;
		solve(n);
	}
}
