#include <bits/stdc++.h>
int main() {
  std::vector<int> v;
  while (1) {
    int count = 0;
    int n;
    std::cin >> n;
    if (n == 0) {
      break;
    }
    std::vector<std::vector<int>> a(n, std::vector<int>(3));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 3; ++j) {
        std::cin >> a[i][j];
      }
    }
    std::vector<int> num(n);
    for (int i = 0; i < n; ++i) {
      for (int j = 1; j < n; ++j) {
        if (a[i][0] == a[j][0]) {
          num[i] += a[i][1] * a[i][2] + a[j][1] * a[j][2];
          ++count;
          break;
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      if (count == 0) {
        v.push_back(0);
      }
      if (num[i] >= 1000000) {
        if (count >= 2) {
          sort(num.begin(), num.end());
        }
        v.push_back(num[i]);
      }
    }
  }
  for (int i = 0; i < v.size(); ++i) {
    if (v[i] == 0) {
      std::cout << "NA" << std::endl;
    } else {
      std::cout << v[i] << std::endl;
    }
  }
  return 0;
}
