#include <bits/stdc++.h>
using namespace std;
int main() {
  int datasuu = 0;
  int flag[4000][4000];
  int sbangou[4000][4000];
  int hanbai[4000][4000];
  int uriage[4000][4000];
  int goukei[4000][4000];
  int kaisuu = 0;
  for (int j = 0;; j++) {
    cin >> datasuu;
    if (datasuu == 0) {
      kaisuu = j;
      break;
    }
    for (int i = 0; i < datasuu; i++) {
      scanf("%d%d%d", &sbangou[j][i], &hanbai[j][i], &uriage[j][i]);
      for (int z = 0; z < i; z++) {
        if (hanbai[j][i] == hanbai[j][z]) {
          goukei[j][i] += goukei[j][z];
        }
      }
      goukei[j][i] += hanbai[j][i] * uriage[j][i];
      if (goukei[j][i] >= 1000000) {
        flag[j][i] = 1;
        goukei[j][i] = hanbai[j][i] * uriage[j][i];
      }
    }
  }
  int on = 0;
  for (int i = 0; i < 4000; i++) {
    for (int j = 0; j < 4000; i++) {
      if (flag[i][j] == 1) {
        cout << sbangou[i][j] << endl;
        on = 1;
      }
      if (on == 0) cout << "NA";
    }
  }
  return 0;
}
