#include<stdio.h>
#include<math.h>
#include<string.h>
int main(){
  int n,d[10],r[60],i,j;
  char s[60][30];
  double e[60],eps=0.000000001;
  while(scanf("%d",&n),n){
  for(i=0;i<n;i++){
    r[i]=i;
    scanf("%s",s[i]);
    for(j=1;j<10;j++)scanf("%d",&d[j]);
    e[i]=1.0*(d[7]*d[8]*d[9]-d[1])/(d[2]+d[3]+d[4]+(d[5]+d[6])*d[9]);
    for(j=i;j;j--){
	if(e[r[j-1]]+eps<e[i]||
	   fabs(e[r[j-1]]-e[i])<eps&&strcmp(s[r[j-1]],s[i])>0)r[j]=r[j-1];
	else break;
    }
    r[j]=i;
  }
  for(i=0;i<n;i++)printf("%s\n",s[r[i]]);
  printf("#\n");
  }
  return 0;
}