#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

#define NMAX 50

typedef struct s{
	string L;
	double P,A,B,C,D,E,F,S,M;
} S;

bool operator<(S a,S b){
	double aa=(a.F*a.S*a.M-a.P)/((a.A+a.B+a.C+a.D+a.E)+(a.D+a.E)*(a.M-1));
	double bb=(b.F*b.S*b.M-b.P)/((b.A+b.B+b.C+b.D+b.E)+(b.D+b.E)*(b.M-1));
	return aa>bb||(aa==bb&&a.L<b.L);
}

int main(){

	int N;
	S data[NMAX];

	while(1){
		cin>>N;
		if(N==0) break;

		for(int i=0;i<N;i++){
			cin>>data[i].L>>data[i].P>>data[i].A>>data[i].B>>data[i].C>>data[i].D>>data[i].E>>data[i].F>>data[i].S>>data[i].M;
		}

		sort(data,data+N);

		for(int i=0;i<N;i++){
			cout<<data[i].L<<endl;
		}
		cout<<"#"<<endl;
	}

}