import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    var n = 0
    while( {n=readInt;n} != 0 ) {
      val b = new ArrayBuffer[Array[Int]]
      for(i<-1 to n) {
        b += readLine.split(" ").map(_.toInt)
      }
      val limit = readLine.split(" ").map(_.toInt)
      val p = limit(0);val q = limit(1);val r = limit(2);val c = limit(3)
      val list = b.toArray.filter { i => i(1) <= p && i(2) <= q && i(3) <= r && i(1)*4 + i(2)*9 + i(3)*4 <= c }
      if(list.length == 0) println("NA")
      else list.foreach(i=>println(i(0)))
    }
  }
}