#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct data {
    int income, time;
    char name[25];
} data;

int comp(const void* a, const void* b)
{
    data x=*((data*)a), y=*((data*)b);
    int p=x.income*y.time, q=y.income*x.time;
    if (p==q) return strcmp(x.name, y.name);
    return p<q;
}

int main(void)
{
    int n;
    while (scanf("%d", &n), n) {
        data v[51];
        int i;
        for(i=0;i<n;++i) {
            char l[26];
            int p,a,b,c,d,e,f,s,m;
            int j, t=0;
            scanf("%s%d%d%d%d%d%d%d%d%d",l,&p,&a,&b,&c,&d,&e,&f,&s,&m);
            strcpy(v[i].name, l);
            v[i].time=(d+e)*m+a+b+c;
            v[i].income=f*s*m-p;
        }
        qsort(v, n, sizeof(data), comp);
        for(i=0;i<n;++i) puts(v[i].name);
        puts("#");
    }
    return 0;
}