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

#define EPS 1e-7

typedef struct {
	char name[21];
	double efficiency;
} Rec;

int compare(const void *a, const void *b) {
	double ta = ((Rec *)a)->efficiency, tb = ((Rec *)b)->efficiency;

	if (fabs(ta - tb) < EPS)
		return strcmp(((Rec *)a)->name, ((Rec *)b)->name);
	else if (tb < ta)
		return -1;
	else
		return 1;
}

Rec rec[50];

int main(void) {
	int i;
	int n;

	while (scanf("%d", &n), n) {
		for (i = 0; i < n; i++) {
			double p, a, b, c, d, e, f, s, m;
			double income, t;

			scanf("%s %lf %lf %lf %lf %lf %lf %lf %lf %lf", rec[i].name, &p, &a, &b, &c, &d, &e, &f, &s, &m);
			income = f * m * s - p;
			t = a + b + c + (d + e) * m;

			rec[i].efficiency = income / t;
		}

		qsort(rec, n, sizeof(Rec), &compare);

		for (i = 0; i < n; i++)
			puts(rec[i].name);
		puts("#");
	}

	return 0;
}