#include <bits/stdc++.h>
int main() {
  int N;
  int n, m, p;
  long P[4003][3] = {};
  long PT[4003][4] = {};
  while (1) {
    scanf("%d", &N);
    if (N == 0) break;
    for (int i = 1; i <= N; i++) {
      scanf("%d %d %d", &n, &m, &p);
      P[n][0] += m * p;
      if (P[n][1] == 0) P[n][1] = i;
    }
    int c = 0;
    for (int i = 0; i <= 4001; i++)
      if (1000000 <= P[i][0]) {
        PT[c][0] = P[i][0];
        PT[c][1] = P[i][1];
        PT[c][2] = i;
        c++;
      }
    for (int i = 0; i < c; i++)
      for (int j = c - 1; j > i; j--)
        if (PT[j][1] < PT[j - 1][1]) {
          long TT = PT[j][1];
          PT[j][1] = PT[j - 1][1];
          PT[j - 1][1] = TT;
          long TTT = PT[j][2];
          PT[j][2] = PT[j - 1][2];
          PT[j - 1][2] = TTT;
        }
    for (int i = 0; i < c; i++) printf("%ld\n", PT[i][2]);
    if (c == 0) printf("NA\n");
    for (int i = 0; i <= 4001; i++) {
      P[i][0] = 0;
      P[i][1] = 0;
      P[i][2] = 0;
      PT[i][0] = 0;
      PT[i][1] = 0;
      PT[i][2] = 0;
      PT[i][3] = 0;
    }
  }
  return 0;
}
