#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long Int;

int main(){
    map<int,Int> table;
    vector<int> ids;
    int n;
    bool flug;

    while(cin >> n, n != 0){
        flug = false;
        table.clear();
        ids.clear();

        for(int i=1; i<=n; i++){
            int id;
            Int tanka;
            Int number;
            cin >> id >> tanka >> number;
            table[id] += (tanka*number);
            vector<int>::iterator fIter = find(ids.begin(), ids.end(), id);
            if(fIter == ids.end()){
                ids.push_back(id);
            }
        }

        for(vector<int>::iterator Iter = ids.begin(); Iter != ids.end(); Iter++){
            if(table[*Iter] >= 1000000){
                cout << *Iter << endl;
                flug = true;
            }
        }

        if(flug == false){
            cout << "NA" << endl;
        }
    }

    return 0;
}
#include <iostream>

int main(int argc, char const* argv[])
{
  int i, n, a, b, a_score, b_score;

  while (true) {
    a_score = 0;
    b_score = 0;

    std::cin >> n;
    if (n == 0) { break; }

    for (i = 0; i < n; i++) {
      std::cin >> a;
      std::cin >> b;

      if (a > b) {
        a_score += (a + b);
      } else if (b > a) {
        b_score += (a + b);
      } else {
        a_score += a;
        b_score += b;
      }
    }
    std::cout << a_score << " " << b_score << std::endl;
  }

  return 0;
}