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

    rs = {}
    for i in range(n):
        arr = input().split(' ')
        s = arr[0] * arr[1]
        rs[arr[0]] = (rs[arr[0]] or 0) + s

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