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


using namespace std;

typedef pair<double, string> P;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    vector<P> v(n);

    for (int i = 0; i < n; i++) {
      string L;
      int p, a, b, c, d, e, f, s, m;
      cin >> L >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      int t = a + b + c + (d + e) * m; 
      double u = (s * f * m - p) / (double)t;
      v[i] = P(u, L);
    }

    sort(v.begin(), v.end(), [](P a, P b) {
      if (a.first > b.first) {
        return true;
      } else if (a.first == b.first) {
        return a.second < b.second;
      } else {
        return false;
      }
    });

    for (int i = 0; i < n; i++) {
      cout << v[i].second << endl;
    }
    cout << "#" << endl;
  }

  return 0;
}