#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0)
            break;
        
        vector< pair<double, string> > 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;
            v[i].first = -(double)(m * f * s -p) / (double)(a + b + c + m*(d + e));
            v[i].second = l;
        }
        sort(v.begin(), v.end());
        for(int i=0; i<n; i++){
            cout << v[i].second << endl;
        }
        cout << '#' << endl;
    }
  
    return 0;
}