#include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n;
	while(scanf("%d",&n)&&n)
	{
		pair<double,string> ans[50];
		REP(i,n)
		{
			char name[21];
			double p,a,b,c,d,e,f,s,m;
			scanf("%s%lf%lf%lf%lf%lf%lf%lf%lf%lf",name,&p,&a,&b,&c,&d,&e,&f,&s,&m);
			ans[i]=make_pair((a+b+c+m*(d+e))/(f*s*m-p),name);
		}
		sort(ans,ans+n);
		
		int mi(0);
		REP(i,n)if(ans[i].first<0)mi++;
//		reverse(ans,ans+mi);
		rotate(ans,ans+mi,ans+n);
		
		REP(i,n){printf("%s\n",ans[i].second.c_str());}
		printf("#\n");
	}
	return 0;
}