import Control.Monad

goodIDs' :: [[Integer]] -> [[Integer]]
goodIDs' [] = []
goodIDs' ([i,p,q]:xs) = do
    let m = p * q
    let ixs = [ [i2 , p2 , q2] | [i2 , p2 , q2] <- xs , i2 == i]
    let rest= [ [i3 , p3 , q3] | [i3 , p3 , q3] <- xs , i3 /= i]
    foldr (\ [_,p10,q10] [i11,m11] -> [i11,m11 + p10 * q10]) [i,m] ixs : goodIDs' rest

goodIDs :: [[Integer]] -> [Integer]
goodIDs = map head . filter (\ [_,m] -> m >= 1000000) . goodIDs'

printResult :: [Integer] -> IO ()
printResult [] = putStrLn "NA"
printResult xs = mapM_ print xs

solve :: Int -> IO ()
solve n = replicateM n getLine
    >>= return . map (map read) . map words
    >>= printResult . goodIDs
    
main :: IO ()
main  = readLn
    >>= (\ n -> if n == 0 then return () else solve n >> main)