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