#!/usr/bin/env python3
import sys

input_lines = sys.stdin.readlines()
cnt = 0
dataset = []
for i in input_lines:
    if not(' ' in i):
        dataset.append([int(i)])
        cnt += 1
    else:dataset[cnt-1].append(list(map(int, i.split(' '))))
    
for d in dataset:
    if d == [0]:pass
    else:
        shain = [[x[0], x[1]*x[2]] for x in d[1:]]
        slist = []
        for s in shain:
            if not(s[0] in slist):slist.append(s[0])
        newslist = [[x, 0] for x in slist]
        score = []
        for s in shain:
            newslist[slist.index(s[0])][1] += s[1]
        
        flag = False
        for n in newslist:
            if n[1] >= 1000000:
                print(n[0])
                flag = True
    if not flag:print('NA')