#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	const int intmax  = 1000010;
	ll int e;
	while(cin >> e,e){
		ll int ans = 9999999;
		FOR(y,0,sqrt((double)e)+2){
			FOR(z,0,cbrt((double)e)+2){
				if(e-y*y-z*z*z>=0) ans = min(ans,y+z+(e-y*y-z*z*z));
			}
		}
		cout << ans << endl;
	}
	
}
#include <iostream>

#include <vector>

#include <algorithm>

#include <set>

#include <queue>

#include <stack>

#include <string>

#include <map>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>



using namespace std;



int main(void){

    int n;

    while (cin >> n, n) {

        vector<pair<double, string> > list;

        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;

            double cost = (-1.0)*(m*s*f-p)/((a+b+c)+m*(d+e));

            list.push_back(make_pair(cost, l));

        }

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

        for (int i = 0; i < list.size(); i++) {

            cout << list[i].second << endl;

        }

        cout << "#" << endl;

    }



	return 0;

}