#include "iostream"
#include "string"
#include "algorithm"
#include "cmath"
#define eps 10e-10
using namespace std;
typedef struct crop
{
	string name;
	double eff;

	static bool comp(const crop& l, const crop& r)
	{
		if(abs(l.eff-r.eff)>eps) return l.eff>r.eff;
		return l.name<r.name;
	}
}crop;


int main(void)
{
	int n;
	while (cin>>n,n) {
		crop in[n];
		for (int i = 0; i < n; i++) {
			cin>>in[i].name;
			int p,a,b,c,d,e,f,s,m;
			cin>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			int t=a+b+c+(d+e)*m;
			in[i].eff=(f*m*s-p)*1.0/t;
		}
		sort(in,in+n,crop::comp);
		for (int i = 0; i < n; i++) {
			cout<<in[i].name<<endl;
		}
		cout<<"#"<<endl;
	}
	return 0;
}