#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
const double EPS=1e-8;
struct data{
    double b;string Name;
    data(double b_,string Name_):b(b_),Name(Name_){}
    data(){}
    bool operator<(const data &d)const{
        return (b-d.b<EPS&&b-d.b>-EPS)?Name>d.Name:b<d.b;
    }
};
int main(){
    int n;
    while(cin>>n,n){
        vector<data>V;
       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;
            int val=f*s*m-p;
            V.push_back(data(1.0*val/t,l));
       }
        sort(V.rbegin(),V.rend());
        for(int i=0;i<n;i++){
            cout<<V[i].Name<<endl;
        }
        cout<<"#"<<endl;
    }
    return 0;
}
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		map<int, long long int>mp;
		vector<int>vs;
		for (int i = 0; i < N; ++i) {
			long long int a, b, c; cin >> a >> b >> c;
			mp[a] += b*c;
			if (find(vs.begin(), vs.end(), a) == vs.end())vs.emplace_back(a);
		}
		bool flag = false;
		for (auto v : vs) {
			if (mp[v] >= 1000000) {
				cout << v << endl;
				flag = true;
			}
		}
		if (!flag)cout << "NA" << endl;
	}
	return 0;
}

