import Control.Monad
import Data.Functor

import qualified Data.Array as Array

main :: IO ()
main = do
    n <- readLn :: IO Int
    if n == 0 then return ()
    else do
        salesData <- replicateM n $ do
            [i, p, q] <- map read <$> words <$> getLine :: IO [Int]
            return (i, p*q)
        let salesArray = Array.accumArray (+) 0 (1, 4000) salesData 
            ids = map fst . filter ((<=) 1000000 . snd) $ Array.assocs salesArray
        if null ids then putStrLn "NA"
        else mapM_ print ids
        main