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

main :: IO ()
main = do
  inputs <- getContentsUntil0
  mapM_ putStrLn $ solve inputs
  
getContentsUntil0 :: IO [[(Int, Int)]]
getContentsUntil0 = do
  c <- readLn :: IO Int
  if c == 0
    then return []
    else do
    cs <- readContents c
    let cs' = map (\x -> (head x, (product . tail) x)) cs
    liftM2 (:) (return cs') getContentsUntil0

readContents :: Int -> IO [[Int]]
readContents n = replicateM n getInts
  
getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: [[(Int, Int)]]-> [String]
solve [] = []
solve (n:ns) = ls' ++ solve ns
  where
    ls = searchEmployee n
    ls' = case ls of
      [] -> ["NA"]
      [-1] -> []
      xs -> foldr (\a b -> show a : b) [] xs
      
searchEmployee :: [(Int, Int)] -> [Int]
searchEmployee [] = []
searchEmployee xs =  map fst $ filter ((>= 1000000).snd) $
                     map (foldl1 (\a b -> (fst b, snd a + snd b))) $
                     groupBy (\a b -> fst a == fst b) $ sort xs