import Control.Monad
import Data.Functor
 
import qualified Data.Array as Array

threshold = 1000000
 
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 const 0 (1, 4000) []
            loop arr [] b = do
              when (not b) $ putStrLn "NA"
              return ()
            loop arr ((i,s):xs) b = do
              let v' = (arr Array.! i) + s
              if v' >= threshold then do
                print i 
                loop (arr Array.// [(i, minBound)]) xs True
              else 
                loop (arr Array.// [(i, v')]) xs b
        loop salesArray salesData False
        main