import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

alias Data = Tuple!(double, string);
void main()
{
	while (1) {
		auto n = readln.chomp.to!int;
		if (!n) break;
		auto data = new Data[](n);
		foreach (i; 0..n) {
			auto x = readln.chomp.split.array;
			data[i][1] = x[0];
			auto p = x[1..$].map!(to!double);
			data[i][0] = ((p[6]*p[7]*p[8]) - p[0]) / (p[1]+p[2]+p[3]+(p[4]+p[5])*p[8]);
		}
		data = data.sort!((a,b) => a[0]==b[0] ? a[1] < b[1] : a[0] > b[0]).array;
		foreach (e; data) {
			e[1].writeln;
		}
		writeln("#");
	}
}