import           System.IO
import           Text.Printf
import           Data.List
import           Control.Monad

data User = User {
  idStr :: String,
  yen :: Int,
  num :: Int
}

toUser :: String -> User
toUser line =
  let l = words line
  in  User {idStr = head l, yen = read $ l !! 1, num = read $ l !! 2}

groupByUser :: [User] -> [[User]]
groupByUser = groupBy (\u1 u2 -> idStr u1 == idStr u2)

foldlUser :: [User] -> (String, Int)
foldlUser = foldl (\acc o -> (idStr o, snd acc + (yen o * num o))) ("", 0)

judgeUser :: [User] -> [(String, Int)]
judgeUser users =
  filter (\o -> snd o >= 1000000) (map foldlUser (groupByUser users))

ex n = do
  users <- replicateM n (fmap toUser getLine)
  let ress = judgeUser users
  if null ress
    then putStrLn "NA"
    else fmap (\_ -> ()) $ mapM (putStrLn . fst) $ ress

main = do
  n <- readLn
  if n == 0 then return () else ex n
  unless (n == 0) main

