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

reshape :: [Int] -> (Int, Int)
reshape xs = (head xs, product (tail xs))

saleResult :: [(Int, Int)] -> [(Int, Int)]
saleResult [] = []
saleResult (x:xs) =
  let ys = filter (\y -> fst y == fst x) xs
      sr = snd x + sum (map snd ys)
  in
      (fst x, sr) : saleResult (xs \\ ys)


solver :: [[Int]] -> [Int]
solver xs =
  let ys = map reshape xs
      cand = saleResult ys
  in map fst $ filter (\c -> snd c >= 1000000) cand

main :: IO()
main = do
  n <- (read :: String -> Int) <$> getLine
  unless (n == 0) $ do
    inputs <- map (map (read :: String -> Int) . words) <$> replicateM n getLine
    let cand = solver inputs
    if null cand
      then putStrLn "NA"
      else mapM_ print cand
    main