import Data.Int (Int64)
import Data.Array.IO
import Data.List (delete,insert)

is1000000 (x,y) = x <= -1000000

putresult arr xs s = do
  s' <- getLine
  let [idx,x,y] = map (read :: String -> Int64) $ words s'
  xy <- readArray arr idx
  writeArray arr idx (xy + x*y)
  xy' <- readArray arr idx

  let xs' = insert (-xy',idx) (delete (-xy,idx) xs)

  print xs'

  if s < 2 then return ()
  else do
     putresult arr xs' (s-1)

  let xs'' = takeWhile is1000000 xs'

  if xs'' == [] then putStrLn "NA"
  else do
    putStr $ unlines $ map show $ map snd xs''

  main

main = do
  s <- readLn
  arr <- newArray (1,4000) 0 :: IO (IOUArray Int64 Int64)
  if s == 0 then return ()
  else do
    putresult arr [] s