import Control.Applicative
import Control.Monad
import Data.List

main = do
    n <- readLn
    if n == 0 then return ()
              else showGoodEmployee n >> main

showGoodEmployee :: Int -> IO ()
showGoodEmployee n = do
      set <- replicateM n $ (\[a,b,c] -> (a,b*c)).map read.words<$>getLine
      let sales = addsales set
      showID $ map fst.filter (\x -> snd x >= 1000000) $ sales

showID :: Show a => [a] -> IO ()
showID [] = putStrLn "NA"
showID xs = mapM_ print xs

addsales :: [(Int,Int)] -> [(Int,Int)]
addsales xs = map (addsale xs) ids
    where
        ids = nub $ map fst xs
        addsale list employeeID = (employeeID, sum.map snd $ filter (\x -> fst x == employeeID) list)