while true
    n = gets.to_i
    break if n == 0
    arr = []
    n.times{
        line = gets.chomp.split.map(&:to_i)
        arr << [line[0], [[line[1], 0], [line[2], 1], [line[3], 2], [line[1] * 4 + line[2] * 9 + line[3] * 4, 3]]]
    }
    limit = gets.chomp.split.map(&:to_i)
    result = []
    arr.each{|name, info| result << name if info.all?{|x, i| x <= limit[i]}}
    puts result.empty? ? "NA" : result
end
