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

"""

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0100&lang=jp

"""

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)



    #for i, sales in enumerate(total_sales):

    #    if sales >= 1000000:

    #        result.append(i)

    return result





def main(args):

    #data = []

    #data.append([1001, 2000, 520])

    #data.append([1002, 1800, 450])

    #data.append([1003, 1600, 625])

    #data.append([1001, 200, 1220])

    while True:

        num = int(eval(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')





if __name__ == '__main__':

    main(sys.argv[1:])
# -*- coding: utf-8 -*-

"""

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0100&lang=jp

"""

import sys

from collections import OrderedDict





def solve(data):

    # ?£???????1,000,000??\????????????ID?????????

    # ??????????????????????????°????????´??????????????????ID?????\??????????????????????????????????????????

    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 list(sums.items()) if value >= 1000000]

    return result







def main(args):

    #data = []

    #data.append([1001, 2000, 520])

    #data.append([1002, 1800, 450])

    #data.append([1003, 1600, 625])

    #data.append([1001, 200, 1220])

    while True:

        num = int(eval(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')





if __name__ == '__main__':

    main(sys.argv[1:])
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0100&lang=jp
"""
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)
    # for i, sales in enumerate(total_sales):
    #    if sales >= 1000000:
    #        result.append(i)
    return result


def main(args):
    # data = []
    # data.append([1001, 2000, 520])
    # data.append([1002, 1800, 450])
    # data.append([1003, 1600, 625])
    # data.append([1001, 200, 1220])
    while True:
        num = int(eval(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")


if __name__ == "__main__":
    main(sys.argv[1:])

# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0100&lang=jp
"""
import sys
from collections import OrderedDict


def solve(data):
    # ?£???????1,000,000??\????????????ID?????????
    # ??????????????????????????°????????´??????????????????ID?????\??????????????????????????????????????????
    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 list(sums.items()) if value >= 1000000]
    return result


def main(args):
    # data = []
    # data.append([1001, 2000, 520])
    # data.append([1002, 1800, 450])
    # data.append([1003, 1600, 625])
    # data.append([1001, 200, 1220])
    while True:
        num = int(eval(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")


if __name__ == "__main__":
    main(sys.argv[1:])

+from collections import OrderedDict -    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) -    # for i, sales in enumerate(total_sales): -    #    if sales >= 1000000: -    #        result.append(i) +    # ?£???????1,000,000??\????????????ID????????? +    # ??????????????????????????°????????´??????????????????ID?????\?????????????????????????????????????????? +    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 list(sums.items()) if value >= 1000000]