#include <bits/stdc++.h>
int ans[4000];
void tasu(int);
int main() {
  int p, q, id;
  int i, j, n, f;
  while (1) {
    scanf("%d", &n);
    if (n == 0) break;
    f = 0;
    j = 0;
    ans[0] = -1;
    for (i = 0; i < n; i++) {
      scanf("%d %d %d", &id, &p, &q);
      if (p >= 1000 && q >= 1000) {
        tasu(id);
        f = 1;
      } else if (p * q >= 1000000) {
        tasu(id);
        f = 1;
      }
    }
    if (f == 0) {
      printf("NA\n");
      continue;
    }
    for (i = 0;; i++) {
      if (ans[i] == -1) break;
      printf("%d\n", ans[i]);
    }
  }
  return 0;
}
void tasu(int a) {
  int i, f = 0, temp;
  for (i = 0;; i++) {
    if (ans[i] == -1) {
      temp = i;
      break;
    }
    if (ans[i] == a) {
      f = 1;
      return;
    }
  }
  ans[temp] = a;
  ans[temp + 1] = -1;
}
