#include <bits/stdc++.h>
using namespace std;
string re(string a) {
  for (int i = 0; i < a.size(); i++) {
    a[i] = 'a' + ('z' - a[i]);
  }
  return a;
}
string eq(string a) {
  string b;
  for (int i = 0; i < 20; i++) b.push_back('A');
  for (int i = 0; i < a.size(); i++) b[i] = a[i];
  return b;
}
int main(void) {
  int n;
  while (1) {
    cin >> n;
    if (n == 0) break;
    vector<string> l(n);
    vector<int> p(n), a(n), b(n), c(n), d(n), e(n), f(n), s(n), m(n);
    for (int i = 0; i < n; i++)
      cin >> l[i] >> p[i] >> a[i] >> b[i] >> c[i] >> d[i] >> e[i] >> f[i] >>
          s[i] >> m[i];
    vector<pair<double, pair<string, int> > > q(n);
    for (int i = 0; i < n; i++) {
      q[i].first = (double)(m[i] * f[i] * s[i] - p[i]) /
                   (a[i] + b[i] + c[i] + m[i] * (d[i] + e[i]));
      q[i].second.first = re(eq(l[i]));
      q[i].second.second = i;
    }
    sort(q.begin(), q.end(), greater<pair<double, pair<string, int> > >());
    for (int i = 0; i < n; i++) {
      cout << l[q[i].second.second] << endl;
    }
    cout << '#' << endl;
  }
  return 0;
}
