#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, cnt = 0, tanka, kazu, sum[4002] = {0};
  char syain[4000][5], *syokika = "GO";
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (i = 0; i < n; i++) {
      scanf("%s", syain[i]);
      scanf("%d", &tanka);
      scanf("%d", &kazu);
      sum[i] = tanka * kazu;
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        if (strcmp(syain[i], syain[j]) == 0 && i != j) {
          sum[i] = sum[i] + sum[j];
          sum[j] = 0;
          strcpy(syain[j], syokika);
        }
      }
    }
    for (i = 0; i < n; i++) {
      if (sum[i] >= 1000000) {
        cnt = 1;
        printf("%s\n", syain[i]);
      }
    }
    if (cnt == 0) {
      printf("NA\n");
    }
    cnt = 0;
  }
  return 0;
}
