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

struct status{
	char l[21];
	double ef;
};

int cmp(const void* a,const void * b){
	struct status *s1 = (struct status *)a;
	struct status *s2 = (struct status *)b;
	if(s1->ef > s2->ef)
		return 0;
	else if(s1->ef < s2->ef)
		return 1;
	else
		return strcmp(s1->l,s2->l);
}

int main(void){
	int n, a, b, c, d, e, f, p, m, s, i, j;
	struct status ss[50];
	while(1){
		scanf("%d%*c",&n);
		if(!n) break;
		for(i = 0;i < n;i++){
			for(j = 0;(ss[i].l[j] = getchar()) != ' ';j++);
			ss[i].l[j] = '\0';
			scanf("%d%d%d%d%d%d%d%d%d%*c",&p,&a,&b,&c,&d,&e,&f,&s,&m);
			ss[i].ef = (double)(m * f * s - p) / (a + b + c + (d + e) * m);
		}
		qsort(ss,n,sizeof(ss[0]),cmp);
		for(i = 0;i < n;i++)
			printf("%s\n",ss[i].l);
		printf("#\n");
	}
	return 0;
}