There is data on sales of your company. Your task is to write a program which identifies good workers.

The program should read a list of data where each item includes the employee ID i, the amount of sales q and the corresponding unit price p. Then, the program should print IDs of employees whose total sales proceeds (i.e. sum of p × q) is greater than or equal to 1,000,000 in the order of inputting. If there is no such employees, the program should print "NA". You can suppose that n < 4000, and each employee has an unique ID. The unit price p is less than or equal to 1,000,000 and the amount of sales q is less than or equal to 100,000.



Input

The input consists of several datasets. The input ends with a line including a single 0. Each dataset consists of:


n (the number of data in the list)
i p q
i p q
:
:
i p q


Output

For each dataset, print a list of employee IDs or a text "NA"

Example

Input

4
1001 2000 520
1002 1800 450
1003 1600 625
1001 200 1220
2
1001 100 3
1005 1000 100
2
2013 5000 100
2013 5000 100
0


Output

1001
1003
NA
2013

Source: aizu | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
while True:
	try:
		n = int(input())
	except:
		break
	if n == 0:
		break
	data = {}
	staff = []
	for i in range(n):
		spam = list(map(int, input().split()))
		if spam[0] in data.keys():
			data[spam[0]] += spam[1] * spam[2]
		else:
			data[spam[0]] = spam[1] * spam[2]
			staff.append(spam[0])
	if max(data.values()) < 1000000:
		print('NA')
	else:
		for i in staff:
			if data[i] >= 1000000:
				print(i)


while True:
	n = int(input())
	if n == 0:
		break
	personel = {}
	for _ in range(n):
		(e, p, q) = input().split()
		if e in personel.keys():
			personel[e] += int(p) * int(q)
		else:
			personel[e] = int(p) * int(q)
	result = []
	for (key, val) in personel.items():
		if val >= 1000000:
			result.append(key)
	if not result:
		print('NA')
	else:
		print('\n'.join(result))


while 1:
	n = int(input())
	if not n:
		break
	f = 1
	L = {}
	for (a, b, c) in [input().split() for i in range(n)]:
		if a in L:
			if L[a] >= 1000000.0:
				continue
			L[a] += int(b) * int(c)
		else:
			L[a] = int(b) * int(c)
		if L[a] >= 1000000.0:
			print(a)
			f = 0
	if f:
		print('NA')


dataCount = int(input())
while dataCount > 0:
	employeeSalesList = []
	for _ in range(dataCount):
		dataList = input().split(' ')
		(employeeId, price) = (dataList[0], int(dataList[1]) * int(dataList[2]))
		for data in employeeSalesList:
			if data[0] == employeeId:
				data[1] += price
				continue
		employeeSalesList.append([employeeId, price])
	answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
	if answerList:
		print('\n'.join(map(str, answerList)))
	else:
		print('NA')
	dataCount = int(input())


employeeSalesList = []

def resetDataset():
	del employeeSalesList[0:len(employeeSalesList) + 1]

def readDataCount():
	return int(input())

def searchEmployeeSales(employeeId):
	for data in employeeSalesList:
		if data[0] == employeeId:
			return data
	newData = [employeeId, 0]
	employeeSalesList.append(newData)
	return newData
answerList = []

def printEmployeeOfDataset():
	found = False
	for data in employeeSalesList:
		if data[1] >= 1000000:
			answerList.append(data[0])
			found = True
	if not found:
		answerList.append('NA')
resetDataset()
dataCount = readDataCount()
while dataCount > 0:
	for _ in range(dataCount):
		(employeeId, price, volume) = list(map(int, input().split(' ')))
		employeeSales = searchEmployeeSales(employeeId)
		employeeSales[1] += price * volume
	printEmployeeOfDataset()
	resetDataset()
	dataCount = readDataCount()
for row in answerList:
	print(row)


while 1:
	n = int(input())
	if n == 0:
		break
	count = 0
	member = [0] * 4001
	mem_check = []
	mem_check2 = []
	for i in range(n):
		(e, p, q) = map(int, input().split())
		member[e] += p * q
		mem_check.append(e)
	for i in mem_check:
		if not i in mem_check2:
			if member[i] >= 1000000:
				print(i)
				count += 1
				mem_check2.append(i)
	if count == 0:
		print('NA')


while 1:
	a = {}
	b = 1
	n = int(input())
	if n == 0:
		break
	for _ in [0] * n:
		(e, p, q) = map(int, input().split())
		a.setdefault(e, 0)
		a[e] += p * q
	for e in a:
		if a[e] >= 1000000.0:
			print(e)
			b = 0
	if b:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	lst = [0] * 4001
	elst = []
	ans = []
	for i in range(n):
		(e, p, q) = map(int, input().split())
		if lst[e]:
			pass
		else:
			elst.append(e)
		lst[e] = lst[e] + p * q
	for i in elst:
		if lst[i] >= 1000000:
			ans.append(i)
	if ans == []:
		print('NA')
	else:
		for i in ans:
			print(i)


import sys
import math
data = [0 for i in range(4000)]
p_data = []
while True:
	n = int(input())
	count = 0
	if n == 0:
		break
	for i in range(n):
		(e, p, q) = map(int, input().split())
		data[e] = data[e] + p * q
		if p_data.count(e) == 0:
			p_data.append(e)
	for i in range(len(p_data)):
		if data[p_data[i]] >= 1000000:
			print(p_data[i])
			count = count + 1
			data[p_data[i]] = 0
		elif data[p_data[i]] != 0:
			data[p_data[i]] = 0
	if count == 0:
		print('NA')
	p_data.clear()


employeeSalesList = []

def resetDataset():
	for count in range(len(employeeSalesList)):
		employeeSalesList.pop(0)

def readDataCount():
	return int(input())

def searchEmployeeSales(employeeId):
	for data in employeeSalesList:
		if data[0] == employeeId:
			return data
	newData = [employeeId, 0]
	employeeSalesList.append(newData)
	return newData

def checkSales():
	(employeeId, price, volume) = list(map(int, input().split(' ')))
	employeeSales = searchEmployeeSales(employeeId)
	employeeSales[1] += price * volume

def printEmployeeOfDataset():
	found = False
	for data in employeeSalesList:
		if data[1] >= 1000000:
			print(data[0])
			found = True
	if not found:
		print('NA')
resetDataset()
dataCount = readDataCount()
while dataCount > 0:
	for _ in range(dataCount):
		checkSales()
	printEmployeeOfDataset()
	resetDataset()
	dataCount = readDataCount()


dataCount = int(input())
while dataCount > 0:
	employeeSalesList = []
	for _ in range(dataCount):
		dataList = input().split(' ')
		(employeeId, price) = (int(dataList[0]), int(dataList[1]) * int(dataList[2]))
		found = False
		for data in employeeSalesList:
			if data[0] == employeeId:
				data[1] += price
				found = True
		if not found:
			employeeSalesList.append([employeeId, price])
	answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
	if answerList:
		print('\n'.join(map(str, answerList)))
	else:
		print('NA')
	dataCount = int(input())


while 1:
	n = int(input())
	if not n:
		break
	f = 1
	L = {}
	for (a, b, c) in [map(int, input().split()) for i in range(n)]:
		a = str(a)
		d = b * c
		if a in L:
			if L[a] >= 1000000.0:
				continue
			L[a] += d
		else:
			L[a] = d
		if L[a] >= 1000000.0:
			print(a)
			f = 0
	if f:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	emp = [0] * 4001
	used = set()
	for i in range(n):
		(e, p, q) = map(int, input().split())
		emp[e] += p * q
		if 1000000 <= emp[e] and e not in used:
			print(e)
			used.add(e)
	if len(used) == 0:
		print('NA')


import sys

def solve(data):
	result = []
	total_sales = [0 for _ in range(4000 + 1)]
	for (id, unit_price, quantity) in data:
		total_sales[id] += unit_price * quantity
		if total_sales[id] >= 1000000:
			if id not in result:
				result.append(id)
	return result

def main(args):
	while True:
		num = int(input())
		if num == 0:
			break
		data = []
		for _ in range(num):
			data.append([int(x) for x in input().split(' ')])
		result = solve(data)
		if result:
			for ele in result:
				print(ele)
		else:
			print('NA')
main(sys.argv[1:])


import collections
while 1:
	li = collections.defaultdict(int)
	emplist = []
	n = int(input())
	if n == 0:
		break
	for i in range(n):
		(emp, prc, num) = list(map(int, input().split()))
		if emp not in emplist:
			emplist.append(emp)
		li[emp] += prc * num
	tmp = True
	for i in emplist:
		if li[i] >= 1000000:
			print(i)
			tmp = False
	if tmp:
		print('NA')
	li.clear()


employeeSalesList = []

def resetDataset():
	del employeeSalesList[0:len(employeeSalesList) + 1]

def readDataCount():
	return int(input())

def searchEmployeeSales(employeeId):
	for data in employeeSalesList:
		if data[0] == employeeId:
			return data
	newData = [employeeId, 0]
	employeeSalesList.append(newData)
	return newData

def checkSales():
	(employeeId, price, volume) = list(map(int, input().split(' ')))
	employeeSales = searchEmployeeSales(employeeId)
	employeeSales[1] += price * volume
answerList = []

def printEmployeeOfDataset():
	found = False
	for data in employeeSalesList:
		if data[1] >= 1000000:
			answerList.append(data[0])
			found = True
	if not found:
		answerList.append('NA')
resetDataset()
dataCount = readDataCount()
while dataCount > 0:
	for _ in range(dataCount):
		checkSales()
	printEmployeeOfDataset()
	resetDataset()
	dataCount = readDataCount()
for row in answerList:
	print(row)


from collections import Counter
while True:
	n = int(input())
	if n == 0:
		break
	counter = Counter()
	for _ in [0] * n:
		(a, b, c) = map(int, input().split())
		counter[a] += b * c
	result = [str(k) for (k, v) in counter.items() if v >= 1000000] or ['NA']
	print('\n'.join(result))


while True:
	no = {}
	n = int(input())
	if n == 0:
		break
	for i in range(n):
		datas = map(int, input().split())
		li = list(datas)
		e = li[0]
		p = li[1]
		q = li[2]
		s = p * q
		if e not in no:
			no[e] = s
		else:
			no[e] += s
	na = True
	for k in no.keys():
		if 1000000 <= no[k]:
			print(k)
			na = False
	if na == True:
		print('NA')


n = int(input())
while n != 0:
	e_ab = {}
	for i in range(n):
		(e, a, b) = map(int, input().split())
		ab = a * b
		if e not in e_ab.keys():
			e_ab[e] = ab
		else:
			e_ab[e] += ab
	c = 0
	for (e, ab) in e_ab.items():
		if ab >= 10 ** 6:
			c += 1
			print(e)
	if c == 0:
		print('NA')
	n = int(input())


import sys
while True:
	n = int(input())
	score = {}
	if n == 0:
		sys.exit()
	for _ in range(n):
		(e, p, q) = [int(i) for i in input().split(' ')]
		score[e] = score.get(e, 0) + p * q
	employee = []
	for e in score:
		if score[e] >= 1000000:
			employee.append(e)
	if len(employee) == 0:
		print('NA')
	else:
		for e in employee:
			print(e)


while True:
	n = int(input())
	if n == 0:
		break
	d = dict()
	order = []
	for _ in range(n):
		(i, p, q) = map(int, input().split())
		d[i] = d[i] + p * q if i in d else p * q
		if i not in order:
			order.append(i)
	b = True
	for o in order:
		if d[o] > 999999:
			print(o)
			b = False
	if b:
		print('NA')


employeeSalesList = []

def resetDataset():
	del employeeSalesList[0:len(employeeSalesList) + 1]

def readDataCount():
	return int(input())

def searchEmployeeSales(employeeId):
	for data in employeeSalesList:
		if data[0] == employeeId:
			return data
	newData = [employeeId, 0]
	employeeSalesList.append(newData)
	return newData

def checkSales():
	(employeeId, price, volume) = list(map(int, input().split(' ')))
	employeeSales = searchEmployeeSales(employeeId)
	employeeSales[1] += price * volume

def printEmployeeOfDataset():
	found = False
	for data in employeeSalesList:
		if data[1] >= 1000000:
			print(data[0])
			found = True
	if not found:
		print('NA')
resetDataset()
dataCount = readDataCount()
while dataCount > 0:
	for _ in range(dataCount):
		checkSales()
	printEmployeeOfDataset()
	resetDataset()
	dataCount = readDataCount()


while True:
	inputCount = int(input())
	if inputCount == 0:
		break
	employeeNumber = []
	employeePrice = []
	while 0 < inputCount:
		inputNum = [int(item) for item in input().split(' ')]
		price = inputNum[1] * inputNum[2]
		if inputNum[0] in employeeNumber:
			index = employeeNumber.index(inputNum[0])
			employeePrice[index] += price
		else:
			employeeNumber.append(inputNum[0])
			employeePrice.append(price)
		inputCount -= 1
	isExist = False
	for index in range(0, len(employeeNumber)):
		if 1000000 <= employeePrice[index]:
			print(employeeNumber[index])
			isExist = True
	if not isExist:
		print('NA')


def parse(i):
	l = input().strip().split()
	return ((i, l[0]), int(l[1]) * int(l[2]))
n = int(input())
while n:
	(ss, d) = ([parse(_) for _ in range(n)], {})
	for s in ss:
		k = s[0][1]
		d[k] = (d[k][0], d[k][1] + s[1]) if k in d else s
	d = [v[0] for v in d.values() if v[1] >= 1000000]
	if d:
		print('\n'.join((k[1] for k in sorted(d))))
	else:
		print('NA')
	n = int(input())


while True:
	num = 0
	n = int(input())
	E_lis = []
	pri_lis = []
	if n == 0:
		break
	for i in range(n):
		(e, p, q) = map(int, input().split())
		if e in E_lis:
			pri_lis[E_lis.index(e)] += p * q
		else:
			E_lis.append(e)
			pri_lis.append(p * q)
	for j in range(len(E_lis)):
		if pri_lis[j] >= 1000000:
			print(E_lis[j])
			num += 1
	if num == 0:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	c = 0
	l = []
	d = {}
	for i in range(n):
		(num, x, y) = map(int, input().split())
		if num in d:
			d[num] = d[num] + x * y
		else:
			d[num] = x * y
			l.append(num)
	for i in l:
		if d[i] >= 1000000:
			print(i)
			c += 1
	if c == 0:
		print('NA')


from sys import stdin
for line in stdin:
	if int(line) == 0:
		break
	isEmpty = True
	record = {}
	for _ in range(int(line)):
		employee = input().split(' ')
		total = int(employee[1]) * int(employee[2])
		if total >= 1000000:
			print(employee[0])
			isEmpty = False
		else:
			e_t = record.get(employee[0])
			if e_t:
				e_t = record.get(employee[0]) + total
				if e_t >= 1000000:
					print(employee[0])
					isEmpty = False
				else:
					record[employee[0]] = e_t
			else:
				record[employee[0]] = total
	record.clear()
	if isEmpty:
		print('NA')


employeeSalesList = []

def resetDataset():
	del employeeSalesList[0:len(employeeSalesList) + 1]

def readDataCount():
	return int(input())

def searchEmployeeSales(employeeId):
	for data in employeeSalesList:
		if data[0] == employeeId:
			return data
	newData = [employeeId, 0]
	employeeSalesList.append(newData)
	return newData

def printEmployeeOfDataset():
	answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
	if len(answerList) == 0:
		print('NA')
	else:
		print('\n'.join(map(str, answerList)))
resetDataset()
dataCount = readDataCount()
while dataCount > 0:
	for _ in range(dataCount):
		(employeeId, price, volume) = list(map(int, input().split(' ')))
		employeeSales = searchEmployeeSales(employeeId)
		employeeSales[1] += price * volume
	printEmployeeOfDataset()
	resetDataset()
	dataCount = readDataCount()


e = []
while 1:
	l = [list(map(int, input().split())) for i in range(int(input()))]
	if not l:
		break
	d = {}
	for i in l:
		if i[0] not in d:
			d[i[0]] = i[1] * i[2]
		else:
			d[i[0]] += i[1] * i[2]
	e.append(d)
f = 0
for i in e:
	f = 0
	for j in i.items():
		if j[1] >= 1000000:
			print(j[0])
			f = 1
	if not f:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	data = {}
	staff = []
	for i in range(n):
		tmp = list(map(int, input().split(' ')))
		if tmp[0] in data:
			data[tmp[0]] += tmp[1] * tmp[2]
		else:
			data[tmp[0]] = tmp[1] * tmp[2]
			staff.append(tmp[0])
	if max(data.values()) < 1000000.0:
		print('NA')
	else:
		for k in staff:
			if data[k] >= 1000000.0:
				print(k)


from collections import OrderedDict
while True:
	d = OrderedDict()
	n = int(input())
	if not n:
		break
	for i in range(n):
		(s, p, m) = map(int, input().strip('\n').split(' '))
		if s in d:
			d[s] += p * m
		else:
			d[s] = p * m
	cnt = 0
	for (k, v) in d.items():
		if v >= 1000000:
			print(k)
			cnt += 1
	if not cnt:
		print('NA')


while True:
	try:
		N = int(input())
		if N == 0:
			break
		ans = []
		dic = {}
		for i in range(N):
			(e, p, q) = map(int, input().split())
			if e in dic:
				dic[e] += p * q
			else:
				dic[e] = p * q
		for (v, m) in dic.items():
			if m >= 1000000:
				ans.append(v)
		if len(ans) == 0:
			ans.append('NA')
		for k in ans:
			print(k)
	except:
		break


import sys
import os
import math
from collections import defaultdict
for s in sys.stdin:
	n = int(s)
	if n == 0:
		break
	d = defaultdict(int)
	keys = []
	for i in range(n):
		(e, p, q) = map(int, input().split())
		d[e] += p * q
		if e not in keys:
			keys.append(e)
	is_exist = False
	for key in keys:
		v = d[key]
		if v >= 1000000:
			print(key)
			is_exist = True
	if not is_exist:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	d = {}
	c = 0
	l = list()
	for _ in range(n):
		(id_, p, q) = map(int, input().split())
		if id_ in d:
			d[id_] += p * q
		else:
			d[id_] = p * q
			l.append(id_)
	for i in l:
		if d[i] >= 1000000:
			print(i)
			c += 1
	if c == 0:
		print('NA')


def searchEmployeeSales(employeeId):
	for data in employeeSalesList:
		if data[0] == employeeId:
			return data
	newData = [employeeId, 0]
	employeeSalesList.append(newData)
	return newData
dataCount = int(input())
while dataCount > 0:
	employeeSalesList = []
	for _ in range(dataCount):
		dataList = input().split(' ')
		(employeeId, price) = (dataList[0], int(dataList[1]) * int(dataList[2]))
		employeeSales = searchEmployeeSales(employeeId)
		employeeSales[1] += price
	answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
	if answerList:
		print('\n'.join(map(str, answerList)))
	else:
		print('NA')
	dataCount = int(input())


while True:
	n = int(input())
	if n == 0:
		break
	d = {}
	e = []
	for i in range(n):
		tmp = list(map(int, input().split(' ')))
		if tmp[0] in d:
			d[tmp[0]] += tmp[1] * tmp[2]
		else:
			d[tmp[0]] = tmp[1] * tmp[2]
			e.append(tmp[0])
	if max(d.values()) < 1000000:
		print('NA')
	else:
		for k in e:
			if d[k] >= 1000000:
				print(k)


l = int(input())
while l != 0:
	k = 0
	A = []
	B = []
	for l in range(0, l):
		li = input().split()
		if li[0] in A:
			i = A.index(li[0])
			B[i] = B[i] + int(li[1]) * int(li[2])
		else:
			A.append(li[0])
			B.append(int(li[1]) * int(li[2]))
	for (j, b) in enumerate(B):
		if b >= 10 ** 6:
			print(A[j])
			k = 1
	if k == 0:
		print('NA')
	l = int(input())


def solve():
	N = int(input())
	if N == 0:
		return False
	E = []
	D = {}
	for i in range(N):
		(e, p, q) = map(int, input().split())
		E.append(e)
		D[e] = D.get(e, 0) + p * q
	cnt = 0
	for e in E:
		if D.get(e, 0) >= 1000000:
			print(e)
			del D[e]
			cnt += 1
	if cnt == 0:
		print('NA')
	return True
while solve():
	...


while True:
	n = int(input())
	if n == 0:
		break
	id = []
	pq = [-1] * 4001
	for i in range(n):
		(e, p, q) = list(map(int, input().split()))
		if pq[e] < 0:
			id.append(e)
			pq[e] = p * q
		else:
			pq[e] += p * q
	f = False
	for e in id:
		if pq[e] >= 1000000:
			print(e)
			f = True
	if not f:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	data = {}
	staff = []
	for i in range(n):
		tmp = list(map(int, input().split(' ')))
		if tmp[0] in data:
			data[tmp[0]] += tmp[1] * tmp[2]
		else:
			data[tmp[0]] = tmp[1] * tmp[2]
			staff.append(tmp[0])
	if max(data.values()) < 1000000:
		print('NA')
	else:
		for k in staff:
			if data[k] >= 1000000:
				print(k)


from collections import OrderedDict
while True:
	n = int(input())
	if n == 0:
		break
	dic = OrderedDict()
	for i in range(n):
		line = input().split()
		key = line[0]
		sales = int(line[1]) * int(line[2])
		if key in dic:
			dic[key] += sales
		else:
			dic[key] = sales
	res = [k for k in dic if dic[k] >= 1000000]
	if len(res) == 0:
		print('NA')
	else:
		[print(k) for k in res]


while True:
	N = int(input())
	if N == 0:
		break
	D = {}
	di = []
	for n in range(N):
		(e, p, q) = input().split()
		p = int(p)
		q = int(q)
		if e not in di:
			di.append(e)
			D[e] = p * q
		else:
			D[e] = D[e] + p * q
	flag = 0
	for dj in di:
		if D[dj] >= 10 ** 6:
			print(dj)
			flag = 1
	if flag == 0:
		print('NA')


n = int(input())
while n != 0:
	earnings = []
	for i in range(0, n):
		a = str.split(input(), ' ')
		if i > 0:
			for j in range(0, len(earnings)):
				if a[0] == earnings[j][0]:
					earnings[j][1] = str(int(earnings[j][1]) + int(a[1]) * int(a[2]))
					break
				if j == len(earnings) - 1:
					earnings.append([a[0], str(int(a[1]) * int(a[2]))])
		else:
			earnings.append([a[0], str(int(a[1]) * int(a[2]))])
	milionear = []
	for i in range(0, len(earnings)):
		if int(earnings[i][1]) >= 1000000.0:
			milionear.append(earnings[i][0])
	if len(milionear) == 0:
		print('NA')
	else:
		for i in range(0, len(milionear)):
			print(milionear[i])
	n = int(input())


while 1:
	n = int(input())
	if not n:
		break
	f = 1
	L = {}
	for (a, b, c) in [map(int, input().split()) for i in range(n)]:
		a = str(a)
		if a in L:
			if L[a] >= 1000000.0:
				continue
			L[a] += b * c
		else:
			L[a] = b * c
		if L[a] >= 1000000.0:
			print(a)
			f = 0
	if f:
		print('NA')


import sys
from collections import OrderedDict

def solve(data):
	sums = OrderedDict()
	for (id, p, q) in data:
		if id in sums:
			sums[id] += p * q
		else:
			sums[id] = p * q
	result = [key for (key, value) in sums.items() if value >= 1000000]
	return result

def main(args):
	while True:
		num = int(input())
		if num == 0:
			break
		data = []
		for _ in range(num):
			data.append([int(x) for x in input().split(' ')])
		result = solve(data)
		if result:
			for ele in result:
				print(ele)
		else:
			print('NA')
main(sys.argv[1:])


while True:
	flg = True
	inf = []
	dic = {}
	n = int(input())
	if n == 0:
		break
	for i in range(n):
		inf.append(list(map(int, input().split())))
		if inf[i][0] in dic:
			tmp = dic[inf[i][0]] + inf[i][1] * inf[i][2]
			dic[inf[i][0]] = tmp
		else:
			dic[inf[i][0]] = inf[i][1] * inf[i][2]
	for (shain_id, sale) in dic.items():
		if sale >= 1000000:
			print(shain_id)
			flg = False
	if flg:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	flag = False
	dic = {}
	for j in range(n):
		(i, p, q) = map(int, input().split())
		if i not in dic:
			dic[i] = [p * q, 0]
		else:
			dic[i][0] += p * q
		if dic[i][0] >= 10 ** 6 and dic[i][1] == 0:
			print(i)
			dic[i][1] = 1
			flag = True
	if flag == False:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	save_list = [0] * 4001
	display_list = []
	for i in range(n):
		(a, b, c) = map(int, input().split())
		save_list[a] += b * c
		if a not in display_list:
			display_list.append(a)
	ans = []
	for i in display_list:
		if save_list[i] >= 1000000:
			ans.append(i)
	if not ans:
		print('NA')
	else:
		for i in ans:
			print(i)


from collections import defaultdict
while True:
	n = int(input())
	if n == 0:
		break
	dv = defaultdict(int)
	for _ in range(n):
		(e, p, q) = list(map(int, input().split()))
		dv[e] += p * q
	count = 0
	for (k, v) in dv.items():
		if v >= 1000000:
			print(k)
			count += 1
	if count == 0:
		print('NA')


while 1:
	n = int(input())
	if not n:
		break
	f = 1
	L = {}
	for (a, b, c) in [input().split() for i in range(n)]:
		d = int(b) * int(c)
		if a in L:
			if L[a] >= 1000000.0:
				continue
			L[a] += d
		else:
			L[a] = d
		if L[a] >= 1000000.0:
			print(a)
			f = 0
	if f:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	s = [-1] * 4001
	id = []
	for i in range(n):
		(e, p, q) = map(int, input().split())
		if s[e] < 0:
			id.append(e)
			s[e] = p * q
		else:
			s[e] += p * q
	ch = True
	for i in id:
		if s[i] >= 1000000:
			print(i)
			ch = False
	if ch:
		print('NA')


import sys, math, os
PYDEV = os.environ.get('PYDEV')
if PYDEV == 'True':
	sys.stdin = open('sample-input.txt', 'rt')
while True:
	N = int(input())
	if N == 0:
		break
	sales = {}
	good = False
	order = []
	for n in range(N):
		(i, p, q) = [int(_) for _ in input().split()]
		if i not in order:
			order.append(i)
		sales[i] = sales.get(i, 0) + p * q
	good = False
	for i in order:
		if sales[i] >= 1000000:
			print(i)
			good = True
	if not good:
		print('NA')


n = int(input())
while n != 0:
	score = {}
	j = 0
	for i in range(n):
		(e, p, q) = list(map(int, input().split()))
		if e in score:
			score[e]['value'] += p * q
		else:
			score[e] = {'value': p * q, 'index': j}
			j += 1
	f = {}
	for (e, v) in score.items():
		if v['value'] >= 1000000:
			f[v['index']] = e
	if len(f) == 0:
		print('NA')
	else:
		for w in sorted(f.items(), key=lambda x: x[0]):
			print(w[1])
	n = int(input())


while True:
	N = int(input())
	if N == 0:
		break
	d = {}
	for n in range(N):
		(num, p, q) = map(int, input().split())
		if num in d:
			d[num][1] += p * q
		else:
			d[num] = [n, p * q]
	else:
		fla = False
		for (k, v) in sorted(d.items(), key=lambda x: x[1][0]):
			if v[1] >= 1000000:
				print(k)
				fla = True
		else:
			if not fla:
				print('NA')


import sys
while True:
	n = int(sys.stdin.readline().rstrip())
	if n == 0:
		break
	members = []
	sales = {}
	for i in range(n):
		(e, p, q) = sys.stdin.readline().rstrip().split(' ')
		if not e in members:
			members.append(e)
			sales[e] = 0
		sales[e] += int(p) * int(q)
	ret = [member for member in members if sales[member] >= 1000000]
	if len(ret) != 0:
		for d in ret:
			print(d)
	else:
		print('NA')


from collections import defaultdict
while True:
	n = int(input())
	if n == 0:
		break
	SALES = defaultdict(int)
	for _ in range(n):
		(id, p, num) = [int(x) for x in input().split()]
		SALES[id] += p * num
	L = [k for (k, v) in SALES.items() if v >= 1000000]
	if len(L) > 0:
		for i in L:
			print(i)
	else:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	sya = {}
	for _ in range(n):
		try:
			(a, b, c) = map(int, input().split())
			sya[a] = sya[a] + b * c
		except KeyError:
			sya[a] = b * c
	k = []
	for i in sya:
		if sya[i] >= 1000000:
			print(i)
		k.append(sya[i] >= 1000000)
	if not any(k) == True:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	id = []
	pq = [-1] * 4001
	for i in range(n):
		(e, p, q) = list(map(int, input().split()))
		if pq[e] < 0:
			id.append(e)
			pq[e] = p * q
		else:
			pq[e] += p * q
	f = False
	for e in id:
		if pq[e] >= 1000000:
			print(e)
			f = True
	if not f:
		print('NA')


while 1:
	n = int(input())
	if not n:
		break
	f = 1
	L = {}
	for (a, b, c) in [input().split() for i in range(n)]:
		d = int(b) * int(c)
		if a in L:
			if L[a] >= 1000000.0:
				continue
			L[a] += d
		else:
			L[a] = d
		if L[a] >= 1000000.0:
			print(a)
			f = 0
	if f:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	res = {}
	li = []
	for i in range(n):
		d = [int(num) for num in input().split(' ')]
		if d[0] - 1 in res:
			res[d[0] - 1] += d[1] * d[2]
		else:
			res[d[0] - 1] = d[1] * d[2]
			li.append(d[0] - 1)
	flag = False
	for i in li:
		if res[i] >= 1000000:
			print(i + 1)
			flag = True
	if flag == False:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	c = 0
	l = []
	d = {}
	for i in range(n):
		(num, x, y) = map(int, input().split())
		if num in d:
			d[num] = d[num] + x * y
		else:
			d[num] = x * y
			l.append(num)
	for i in l:
		if d[i] >= 1000000:
			print(i)
			c += 1
	if c == 0:
		print('NA')


while True:
	num = int(input())
	if num == 0:
		break
	else:
		li = []
		d = {}
		for i in range(num):
			info = list(map(int, input().split()))
			try:
				d[info[0]] += info[1] * info[2]
			except:
				d[info[0]] = info[1] * info[2]
				li.append(info[0])
	answer = []
	for i in li:
		if d[i] >= 1000000:
			answer.append(i)
	if answer == []:
		print('NA')
	else:
		for i in answer:
			print(i)


while True:
	n = int(input())
	if n == 0:
		break
	workers = {}
	workernames = []
	greatworkers = 0
	for i in range(n):
		(person, price, number) = map(int, input().split())
		if person in workers:
			workers[person] += price * number
		else:
			workers[person] = price * number
			workernames.append(person)
	for worker in workernames:
		if workers[worker] >= 1000000:
			print(worker)
			greatworkers += 1
	if greatworkers == 0:
		print('NA')


def parseData(line):
	dataList = line.split(' ')
	return (int(dataList[0]), int(dataList[1]) * int(dataList[2]))
dataCount = int(input())
while dataCount > 0:
	employeeSalesList = []
	for _ in range(dataCount):
		(employeeId, price) = parseData(input())
		found = False
		for data in employeeSalesList:
			if data[0] == employeeId:
				data[1] += price
				found = True
		if not found:
			employeeSalesList.append([employeeId, price])
	answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
	if answerList:
		print('\n'.join(map(str, answerList)))
	else:
		print('NA')
	dataCount = int(input())


while True:
	n = int(input())
	if n == 0:
		break
	result = {}
	order = []
	for i in range(n):
		(e, p, q) = map(int, input().split())
		if e in result:
			result[e] += p * q
		else:
			result[e] = p * q
			order.append(e)
	flag = True
	for e_i in order:
		if result[e_i] >= 1000000:
			print(e_i)
			flag = False
	if flag:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	data = {}
	staff = []
	for i in range(n):
		tmp = [int(el) for el in input().split(' ')]
		if tmp[0] in data:
			data[tmp[0]] += tmp[1] * tmp[2]
		else:
			data[tmp[0]] = tmp[1] * tmp[2]
			staff.append(tmp[0])
	if max(data.values()) < 1000000.0:
		print('NA')
	else:
		for k in staff:
			if data[k] >= 1000000.0:
				print(k)


while True:
	n = int(input())
	if n == 0:
		break
	l = []
	d = {}
	for _ in range(n):
		(a, b, c) = list(map(int, input().split()))
		if a in d:
			d[a] += b * c
		else:
			d[a] = b * c
			l.append(a)
	if max(d.values()) < 1000000:
		print('NA')
	else:
		for k in l:
			if d[k] >= 1000000:
				print(k)


while True:
	n = int(input())
	if n == 0:
		break
	data = [0] * 4001
	order = []
	for _ in range(n):
		(e, p, q) = map(int, input().split())
		data[e] += p * q
		if e not in order:
			order.append(e)
	flag = True
	for e in order:
		if data[e] >= 1000000:
			print(e)
			flag = False
	if flag:
		print('NA')


while True:
	input_n = int(input())
	key = 0
	if input_n == 0:
		break
	id_list = [[0 for i in range(2)] for i in range(input_n)]
	for i in range(input_n):
		id_line = input().split()
		for j in id_list:
			if j[0] == int(id_line[0]):
				j[1] += int(id_line[1]) * int(id_line[2])
				uriage = j[1]
				break
		else:
			id_list[i][0] = int(id_line[0])
			id_list[i][1] = int(id_line[1]) * int(id_line[2])
			uriage = id_list[i][1]
		if uriage >= 1000000:
			key = 1
	for i in id_list:
		if key == 0:
			print('NA')
			break
		if i[1] >= 1000000:
			print(i[0])


while True:
	n = int(input())
	if n == 0:
		break
	data = {}
	staff = []
	for i in range(n):
		(x, y, z) = [int(el) for el in input().split(' ')]
		if x in data:
			data[x] += y * z
		else:
			data[x] = y * z
			staff.append(x)
	if max(data.values()) < 1000000.0:
		print('NA')
	else:
		for k in staff:
			if data[k] >= 1000000.0:
				print(k)


def searchEmployeeSales(employeeId):
	for data in employeeSalesList:
		if data[0] == employeeId:
			return data
	newData = [employeeId, 0]
	employeeSalesList.append(newData)
	return newData

def printEmployeeOfDataset():
	answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
	if answerList:
		print('\n'.join(map(str, answerList)))
		return
	print('NA')
dataCount = int(input())
while dataCount > 0:
	employeeSalesList = []
	for _ in range(dataCount):
		(employeeId, price, volume) = list(map(int, input().split(' ')))
		employeeSales = searchEmployeeSales(employeeId)
		employeeSales[1] += price * volume
	printEmployeeOfDataset()
	dataCount = int(input())


from collections import OrderedDict
while True:
	n = int(input())
	if n == 0:
		break
	box = OrderedDict()
	for _ in [None] * n:
		(e, p, q) = map(int, input().split())
		if e in box:
			box[e] += p * q
		else:
			box[e] = p * q
	check = 0
	for _ in box:
		if box[_] >= 10 ** 6:
			print(_)
			check = 1
	if check == 0:
		print('NA')


from collections import OrderedDict
while True:
	n = int(input())
	if n == 0:
		break
	ans = OrderedDict()
	for i in range(n):
		(e, p, q) = [int(x) for x in input().split()]
		if e in ans:
			ans[e] += p * q
		else:
			ans[e] = p * q
	flag = True
	for (k, v) in ans.items():
		if v >= 1000000:
			flag = False
			print(k)
	if flag:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	oe = []
	for i in range(n):
		(e, p, q) = map(int, input().split())
		for a in oe:
			if a[0] == e:
				a[1] += p * q
				continue
		oe.append([e, p * q])
	lis = [a[0] for a in oe if a[1] >= 1000000]
	if len(lis):
		print('\n'.join((str(l) for l in lis)))
	else:
		print('NA')


while 1:
	n = int(input())
	if n == 0:
		break
	a = {}
	c = []
	for _ in range(n):
		b = list(map(int, input().split()))
		if b[0] in a:
			a[b[0]] += b[1] * b[2]
		else:
			a[b[0]] = b[1] * b[2]
			c.append(b[0])
	if max(a.values()) <= 999999:
		print('NA')
	for i in c:
		if a[i] > 999999:
			print(i)


while True:
	n = int(input())
	if not n:
		break
	dic = {}
	for i in range(n):
		(e, p, q) = map(int, input().split())
		if e in dic:
			dic[e] = (dic[e][0], dic[e][1] + p * q)
		else:
			dic[e] = (i, p * q)
	lst = []
	for k in dic:
		if dic[k][1] >= 1000000:
			lst.append((dic[k][0], k))
	lst.sort()
	if lst:
		for e in lst:
			print(e[1])
	else:
		print('NA')


from collections import OrderedDict
while True:
	num = int(input())
	if not num:
		break
	result = OrderedDict()
	for _ in range(num):
		(x, y, z) = [int(el) for el in input().split(' ')]
		if x in result:
			result[x] += y * z
		else:
			result[x] = y * z
	res = [print(k) for (k, v) in result.items() if v >= 1000000.0]
	if not res:
		print('NA')


while True:
	try:
		n = int(input())
		if n == 0:
			break
		no = []
		total = []
		for i in range(n):
			(e, p, q) = map(int, input().split())
			if e not in no:
				no.append(e)
				total.append(p * q)
			else:
				ind = no.index(e)
				total[ind] += p * q
		cnt = 0
		for (j, k) in enumerate(total):
			if k >= 1000000:
				cnt += 1
				print(no[j])
		if cnt == 0:
			print('NA')
	except EOFError:
		break


while True:
	n = int(input())
	if n == 0:
		break
	d = dict()
	sep = []
	for _ in range(n):
		(i, p, q) = map(int, input().split())
		if i in d:
			d[i] += p * q
		else:
			d[i] = p * q
			sep.append(i)
	tmp = list(filter(lambda x: x[1] >= 1000000, d.items()))
	if len(tmp):
		tmp = {t[0]: t[1] for t in tmp}
		for s in sep:
			if s in tmp:
				print(s)
	else:
		print('NA')


while True:
	n = int(input())
	if n == 0:
		break
	c = 0
	l = []
	d = {}
	for i in range(n):
		(num, x, y) = [int(i) for i in input().split()]
		if num in d:
			d[num] = d[num] + x * y
		else:
			d[num] = x * y
			l.append(num)
	for i in l:
		if d[i] >= 1000000:
			print(i)
			c += 1
	if c == 0:
		print('NA')


from collections import OrderedDict
while True:
	n = int(input())
	if not n:
		break
	ds = OrderedDict()
	for _ in range(n):
		(i, p, q) = input().split()
		ds[i] = ds.get(i, 0) + int(p) * int(q)
	ds = OrderedDict(((i, v) for (i, v) in ds.items() if v >= 1000000))
	if ds:
		print('\n'.join(ds.keys()))
	else:
		print('NA')


p = []
q = []
while True:
	n = int(input())
	m = 0
	number = [0] * 4000
	if n == 0:
		break
	else:
		for i in range(n):
			p.append(i)
			q.append(i)
			(e, p[i], q[i]) = [int(s) for s in input().split(' ')]
			if number[e] >= 1000000:
				break
			else:
				number[e] = number[e] + p[i] * q[i]
				if number[e] >= 1000000:
					print(e)
				else:
					m = m + 1
			if m == n:
				print('NA')


import sys
from collections import OrderedDict

def solve():
	while True:
		n = int(sys.stdin.readline())
		if n == 0:
			break
		emps = OrderedDict()
		for i in range(n):
			(no, price, amount) = map(int, sys.stdin.readline().split(' '))
			emps[no] = emps.get(no, 0) + price * amount
		results = [k for (k, v) in emps.items() if v >= 1000000]
		if len(results) > 0:
			[print(emp) for emp in results]
		else:
			print('NA')
solve()