#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
    char name[30];
    double cost;
}Crop;
Crop crop[50];
int comp(const void *a,const void *b){
    Crop c = *(Crop *)a;
    Crop d = *(Crop *)b;
    if(c.cost<d.cost) return 1;
    else if(c.cost>d.cost) return -1;
    else{
        int len1=strlen(c.name),len2=strlen(d.name);
        int len=((len1<len2)?len1:len2);
        for(int i=0;i<len;i++){
            if(c.name[i]-'a'<d.name[i]-'a') return -1;
            else if(c.name[i]-'a'>d.name[i]-'a') return 1;
        }
        if(len1<len2) return -1;
        else return 1;
    }
    return 0;
}
int main(void){
    while(1){
        int n;
        scanf("%d",&n);
        if(n==0) break;
        for(int i=0;i<n;i++){
            int p,a,b,c,d,e,f,s,m;
            scanf("%s%d%d%d%d%d%d%d%d%d",
                  crop[i].name,&p,&a,&b,&c,&d,&e,&f,&s,&m);
            //printf("%s%d%d%d%d%d%d%d%d%d\n",crop[i].name,p,a,b,c,d,e,f,s,m);
            //printf("%s:%lu\n",crop[i].name,strlen(crop[i].name));
            int time=a+b+c+(d+e)*m;
            int income=f*s*m-p;
            crop[i].cost=1.0*income/time;
        }
        qsort(crop,n,sizeof(Crop),comp);
        for(int i=0;i<n;i++){
            printf("%s\n",crop[i].name);
            //printf("%s %f\n",crop[i].name,crop[i].cost);
        }printf("#\n");
    }
}

