#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
vl v;



int main(){
	int n,p,a,b,c,d,e,f,s,m;
	string l;
	pair<double,string> seed[50];
	while(1){
		cin>>n;
		if(n==0)break;
		rep(i,n){
			cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			double time=a+b+c+(d+e)*m,price=f*s*m-p;
			double cospa=-1*price/time;
			seed[i].first=cospa;
			seed[i].second=l;
		}
		sort(seed,seed+n);
		rep(i,n)cout<<seed[i].second<<endl;
		cout<<"#"<<endl;
	}

}
