import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

int[] calc(int[] a) {
	int t;
	int p;
	t = a[1] + a[2] + a[3] + (a[4] + a[5]) * a[8];
	p = a[6] * a[7] * a[8] - a[0];
	return [t, p];
}

void main(){
	while(true) {
		auto n = readInt();
		if(n == 0) return;

		alias A = Tuple!(string, "name", int[], "tp");
		A[] a;
		for(int i; i < n; ++i) {
			auto s = readln().chomp.split;
			a ~= A(s[0], calc(s[1..$].map!(to!int).array));
		}
		a.sort!((x,y) => x.tp[1] * y.tp[0] > x.tp[0] * y.tp[1] || (x.tp[1] * y.tp[0] == x.tp[0] * y.tp[1] && x.name < y.name));
		a.each!(x => writeln(x.name));
		writeln("#");
	}
}