l = int(eval(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(eval(input()))
while True:

	N= int(eval(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")

	
l = int(eval(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(eval(input()))

while True:
    N = int(eval(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")

-l = int(eval(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])) +while True: +    N = int(eval(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 -            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: +            D[e] = D[e] + p * q +    flag = 0 +    for dj in di: +        if D[dj] >= 10**6: +            print(dj) +            flag = 1 +    if flag == 0: -    l = int(eval(input()))