#include <bits/stdc++.h>
using namespace std;
string int_to_str(int n) {
  stringstream ss;
  string ret;
  ss << n;
  ss >> ret;
  return ret;
}
int keta(int n) {
  string str = int_to_str(n);
  return str.size();
}
int main() {
  int n;
  while (cin >> n, n) {
    bool f = false;
    map<int, long long> datas;
    vector<int> noes;
    for (int i = 0; i < n; ++i) {
      int no, a, b;
      cin >> no >> a >> b;
      if (find(noes.begin(), noes.end(), no) == noes.end()) noes.push_back(no);
      if (datas[no] < 1000000) {
        if (keta(a) + keta(b) - 2 >= 6)
          f = true;
        else if ((datas[no] += a * b) >= 1000000)
          f = true;
      }
    }
    for (int i = 0; i < noes.size(); ++i)
      if (datas[noes[i]] >= 1000000) cout << noes[i] << endl;
    if (!f) cout << "NA" << endl;
  }
}
