### main

while true
  n = gets.strip.to_i
  break if n == 0

  foods = []

  n.times do
    i, p, q, r = gets.strip.split(' ').map{|s| s.to_i}
    c = 4 * p + 9 * q + 4 * r
    foods << [i, p, q, r, c]
  end
  #p foods

  max_p, max_q, max_r, max_c = gets.strip.split(' ').map{|s| s.to_i}

  edible = 0
  for fd in foods
    if fd[1] <= max_p && fd[2] <= max_q && fd[3] <= max_r && fd[4] <= max_c
      puts fd[0]
      edible += 1
    end
  end

  if edible == 0
    puts 'NA'
  end
end