#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, A, sult[4001], sell[4001], suu[4001];
  while (1) {
    cin >> n;
    if (n == 0) break;
    for (int i = 0; i < n; i++) {
      cin >> sult[i] >> sell[i] >> suu[i];
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i != j && sult[i] == sult[j]) {
          sell[j] = sell[i] * suu[i] + sell[j] * suu[j];
          suu[j] = 1;
          sell[i] = 0;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (sell[i] * suu[i] >= 1000000) {
        cout << sult[i] << "\n";
        A = 1;
      }
    }
    if (A == 0) cout << "NA\n";
    A = 0;
  }
}
