Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}
		sales := make(map[string]int)
		existed := make(map[string]bool)
		order := make([]string, 4000)
		flg := false
		for i := 0; i < n; i++ {
			stdin.Scan()
			l := strings.Split(stdin.Text(), " ")
			e := l[0]
			p, _ := strconv.Atoi(l[1])
			q, _ := strconv.Atoi(l[2])
			sales[e] += p * q
			if !existed[e] {
				order = append(order, e)
				existed[e] = true
			}
		}
		for _, v := range order {
			if sales[v] >= 1000000 {
				fmt.Println(v)
				flg = true
			}
		}
		if flg == false {
			fmt.Println("NA")
		}
	}
}

Python: # -*- coding: utf-8 -*-

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)

    # remove dup
    is_exist = False

    for key in keys:
        v = d[key]
        if v >= 1000000:
            print(key)
            is_exist = True

    if not is_exist:
        print('NA')

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

Python: while True:
    n = int(input())
    x = []
    if n == 0:
        break
    d = [0]*4000
    for i in range(n):
        e,p,q = map(int,input().split())
        d[e] += p*q
    flag = 0
    for i in range(4000):
        if d[i] >= 1000000:
            print(i)
            flag = 1
    if flag == 0:
        print('NA')

Python: while True :
    n = int(input())
    if n == 0 : break
    
    box = {}
    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')

Python: 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")

Python: 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)

Python: while True:
	n = int(input())
	if n == 0:
		break
	workers = {}
	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
	for worker in workers:
		if workers[worker] >= 1000000:
			print(worker)
			greatworkers += 1	
	if greatworkers == 0:
		print('NA')

Python: while True:
	n=int(input())
	if n:
		a=[list(map(int,input().split())) for _ in range(n)]
		b={}
		for i in range(n):
			if a[i][0] in b:
				b[a[i][0]]+=a[i][1]*a[i][2]
			else:
				b[a[i][0]]=a[i][1]*a[i][2]
		for k in b.keys():
			if b[k]>=1000000:
				print(k)
		if max(b.values())<1000000:
			print("NA")
	else:
		break

Python: # coding: utf-8
# Here your code !
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())

Python: while True:
    n = int(input())
    if n == 0:
        break

    rs = {}
    for i in range(n):
        cid, p, q = map(int, input().strip().split(' '))
        rs[cid] = (rs.get(cid, None) or 0) + p * q

    top = [k for k, v in rs.items() if v >= 1000000]
    if len(top) == 0:
        print('NA')
    else:
        for i in top:
            print(i)

Python: while True:
    no = []
    n = int(input())
    if (n == 0):
        exit
    
    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 (1000000 < s and (e in no) == False):
            print(e)
            no.append(e)
    
    if (len(no) == 0):
        print("NA")

Python: # Edit: 2014/09/25
# Lang: Python3
# Time: 0.xxs
#

if __name__ == "__main__":

    while True:
        d = {}
        n = int(input())
        if not n:
            break  # exit at n=0

        for i in range(n):
            s, p, m = map(int, input().strip("\n").split(" "))
            # print(s, p, m)

            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")

        #print(d)

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

Python: 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)

Python: #!/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]:break
    shain = [[x[0], x[1]*x[2]] for x in d[1:]]
    #score = [ 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 = []

Python: while True:
    n = int(input())
    x = []
    if n == 0:
        break
    d = [0]*4000
    for i in range(n):
        e,p,q = map(int,input().split())
        d[e] += p*q
    flag = 0
    for i in range(4000):
        if d[i] >= 1000000:
            x.append(i)
            flag = 1
    if flag == 0:
        print('NA')
    else:
        for i in range(len(x)):
            print(x[i])