/*
AizuOnline A2198
title Moonlight Farm
*/
#include <stdio.h>
#include <stdlib.h>
#define NOOFPLANT 50
int N;
struct Pl_st 
{ char L[21];   //name
  int  P;       //price
  int  A;
  int  B;
  int  C;
  int  D;
  int  E;
  int  F;
  int  S;
  int  M;
} 
plant[NOOFPLANT];
//
compare(void * x,void * y)
{return(shuuritu((struct pl_st *)y)-shuuritu((struct pl_st *)x));
}
int shuuritu(struct Pl_st * pp)
{
  int time;
  int income;
  int mergin;

  time=pp->A+pp->B+pp->C+(pp->D+pp->E)*pp->M;
  income=pp->F*pp->S*pp->M;
  mergin =income-pp->P;
  return(mergin/time);
}
main()
{
  int i;
  struct Pl_st *pp;

  while(EOF!=scanf("%d ",&N) && N)
    {
      for(i=0;i<N;i++)
	{
	  pp=&plant[i];
	  scanf("%s ",(char *)&(pp->L));
	  scanf("%d ",&(pp->P));
	  scanf("%d ",&(pp->A));
	  scanf("%d ",&(pp->B));
	  scanf("%d ",&(pp->C));
	  scanf("%d ",&(pp->D));
	  scanf("%d ",&(pp->E));
	  scanf("%d ",&(pp->F));
	  scanf("%d ",&(pp->S));
	  scanf("%d ",&(pp->M));
	}
      qsort(plant,N,sizeof(struct Pl_st),(__compar_fn_t)compare);

      for(i=0;i<N;i++)
	printf("%s\n",plant[i].L);
      printf("#\n");
    }
return(0);
}