import Control.Monad

main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      ls <- replicateM n getLine
      pqrc <- getLine
      let ls' = map (map read . words) ls
          pqrc' = map read .  words $ pqrc
      mapM_ putStrLn $ solve ls' pqrc'
      main
      
solve :: [[Int]] -> [Int] -> [String]
solve ls pqrc
  | checkedL == [] = ["NA"]
  | otherwise = reverse checkedL
  where
    checkedL = foldl check [] ls
    check :: [String] -> [Int] -> [String]
    check acc item = check' acc item pqrc
      where
        check' :: [String] -> [Int] -> [Int] -> [String]
        check' acc [i,pi,qi,ri] [p,q,r,c]
          | pi <= p && qi <= q && ri <= r && (pi * 4 + qi * 9 + ri * 4) <= c = (show i):acc
          | otherwise = acc