#include <bits/stdc++.h>
using namespace std;
void shoki();
void henkan(string);
int tansaku(int);
pair<string, long long> num[10000];
int n, ban, tanka, kazu, i, j, memo;
bool dp[10000] = {false};
int main() {
  int al = 0;
  bool y = false;
  while (1) {
    shoki();
    cin >> n;
    if (n == 0) {
      break;
    }
    int count = 0;
    for (i = 0; i < n; i++) {
      cin >> num[i].first >> tanka >> kazu;
      henkan(num[i].first);
      if (dp[memo] == true) {
        num[tansaku(i)].second += tanka * kazu;
      } else {
        num[i].second += tanka * kazu;
      }
      dp[memo] = true;
      memo = 0;
    }
    for (int k = 0; k <= i; k++) {
      if (num[k].second == 0) {
        continue;
      }
      if (num[k].second >= 1000000) {
        y = true;
        cout << num[k].first << endl;
      }
    }
    if (y == false) {
      cout << "NA" << endl;
    }
    y = false;
    shoki();
    memset(dp, false, sizeof(dp));
  }
  return 0;
}
void shoki() {
  for (int i = 0; i < 4001; i++) {
    num[i].first = "0";
    num[i].second = 0;
  }
  return;
}
void henkan(string str1) {
  long long kake = 1;
  for (int i = 0; i < str1.size(); i++) {
    memo += str1[i] * i;
    i *= 10;
  }
  return;
}
int tansaku(int rec) {
  int res;
  for (int l = 0; l < rec; l++) {
    if (num[rec].first == num[l].first) {
      return res = l;
    }
  }
}
