// Aizu 2198: Moonlight Farm
// 2017.9.21 bal4u@uu

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

#define EPS 1e-7

typedef struct { char nm[23]; double p; } T;
T tbl[53];

int cmp(T *a, T *b) {
	if (fabs(b->p - a->p) <= EPS) return strcmp(a->nm, b->nm);
	if (a->p <= b->p) return 1; else return -1;
}

int main()
{
	int n, i, p, a, b, c, d, e, f, s, m;
	int t, x;

	while (scanf("%d", &n) && n) {
		for (i = 0; i < n; i++) {
			scanf("%s%d%d%d%d%d%d%d%d%d", tbl[i].nm, &p, &a, &b, &c, &d, &e, &f, &s, &m);
			t = (a+b+c+d+e)*m - (a+b)*(m-1);
			x = (f*s - p)*m;
			tbl[i].p = (double)x / (double)t;
		}
		qsort(tbl, n, sizeof(T), cmp);
		for (i = 0; i < n; i++) puts(tbl[i].nm);
		puts("#");
	}
	return 0;
}