loop do
    n = gets.to_i
    break if n == 0
    a = (1..n).map { gets.split.map(&:to_i) }
    limit = gets.split.map(&:to_i)
    ans = a.select {|s, p, q, r| p <= limit[0] and q <= limit[1] and r <= limit[2] and 4 * p + 9 * q + 4 * r  <= limit[3]}
    if ans.empty?
        puts 'NA'
    else
        puts ans.map {|r| r[0]}
    end
end
