#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(pair<double,string> a, pair<double,string> b){
	if( a.first > b.first ) return true;
	else if( a.first < b.first ) return false;
	return a.second < b.second;
}
int main(){
	int n,A,B,C,D,E,F,S,M,P;
	string name;
	
	while(cin>>n,n){
		vector< pair<double,string> > vp;
		for(int i=0; i<n; i++){
			cin>>name>>P>>A>>B>>C>>D>>E>>F>>S>>M;
			double d = (double)(F*M*S-P)/((double)A+B+C+(D+E)*M);
			vp.push_back( make_pair( d, name) );
		}
		sort(vp.begin(),vp.end(),cmp);
		for(int i=0; i<vp.size(); i++){
			cout << vp[i].second << endl;
		}
		puts("#");
	}
	return 0;
}