#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

struct data_t {
	string name;
	double eff;

	bool operator<(const data_t& right) const {
		if (eff == right.eff) {
			return (name < right.name);
		}
		else {
			return (eff > right.eff);
		}
	}
};

int main(void) {
	int N;
	while (cin >> N, N) {
		vector<data_t> data(N);
		int p,temp,d,e,f,m,s;
		for (int i = 0; i < N; ++i) {
			cin >> data[i].name;
			cin >> p; 
			int time = 0;
			for (int i = 'A'; i <= 'C'; ++i) {
				cin >> temp;
				time += temp;
			}
			cin >> d >> e >> f >> s >> m;
			time += m * (d + e);
			data[i].eff = (double)((f * m * s) - p)/(double)time;
		}

		sort(data.begin(),data.end());

		for (int i = 0; i < N; ++i) {
			cout << data[i].name << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

struct f {
    string l;
    int  p, a, b, c, d, e, f, s, m;
    double rate;
    void input() {
        cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
    }
    void calc() {
        double k = 0;
        rep(i, m) {
            if (i == 0) k += a+b+c+d+e;
            else k += d+e;
        }
        double kk = (f*m*s)-p;
        rate = kk/k;
    }
    void print() {
        cout << l << endl;
    }
};

int main() {
    int n;
    int count = 0;
    while (cin >> n) {
        if (n == 0) break;
        vector<f> a(n);
        rep(i, n) {
            a[i].input();
            a[i].calc();
        }
        sort(a.begin(), a.end(), [](const f& a, const f& b) {
            if (a.rate == b.rate) {
                return a.l < b.l;
            }
            return a.rate > b.rate;
        });
        rep(i, n) {
            a[i].print();
        }
        cout << "#" << endl;
    }
    return 0;
}

