#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

class Plant{
public:
	string name;
	int d,m;
	bool operator<(const Plant plant)const{
		if(m*plant.d==plant.m*d){
			return name<plant.name;
		}else{
			return m*plant.d>plant.m*d;
		}
	}
};

vector<Plant> plants;

int main() {
	int n;
	while(n=in()){
		plants.clear();
		string l;
		int p,a,b,c,d,e,f,s,m;
		int i;
		for(i=0;i<n;i++){
			cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			Plant plant;
			plant.name=l;
			plant.d=a+b+c+(d+e)*m;
			plant.m=f*s*m-p;
			plants.push_back(plant);
		}
		sort(plants.begin(),plants.end());
		for(i=0;i<n;i++){
			cout<<plants[i].name<<endl;
//cout<<plants[i].d<<" "<<plants[i].m<<endl;
		}
		cout<<"#\n";
	}
	return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	while (cin >> n, n)
	{
		long int ary[5001] = {};

		for (int i = 1; i <= n; i++)
		{
			cin >> ary[i];
		}
		for (int i = 1; i <= n; i++)
		{
			ary[i] += ary[i - 1];
		}

		long int ans = -9999999999;
		for (int i = 0; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				ans = max(ans, ary[j] - ary[i]);
			}
		}
		cout << ans << endl;
	}

	return 0;
}