while 1:

    n=int(eval(input()))

    if n==0:break

    a=[[0]*5for _ in range(n)]

    for i in range(n):

        a[i][:4]=list(map(int,input().split()))

        a[i][4]=4*(sum(a[i][1:4:2]))+9*a[i][2]

    p,q,r,c=list(map(int,input().split()))

    f=1

    for i in range(n):

        if a[i][1]<=p and a[i][2]<=q and a[i][3]<=r and a[i][4]<=c:print((a[i][0]));f=0

    if f:print('NA')
while 1:

    n=int(input())

    if n==0:break

    a=[list(map(int,input().split())) for _ in range(n)]

    p,q,r,c=map(int,input().split())

    b=[x[0] for x in a if x[1]<=p and x[2]<=q and x[3]<=r and 4*(x[1]+x[3])+9*x[2]<=c]

    if len(b):print(*b,sep='\n')

    else:print('NA')

while 1:
    n = int(eval(input()))
    if n == 0:
        break
    a = [[0] * 5 for _ in range(n)]
    for i in range(n):
        a[i][:4] = list(map(int, input().split()))
        a[i][4] = 4 * (sum(a[i][1:4:2])) + 9 * a[i][2]
    p, q, r, c = list(map(int, input().split()))
    f = 1
    for i in range(n):
        if a[i][1] <= p and a[i][2] <= q and a[i][3] <= r and a[i][4] <= c:
            print((a[i][0]))
            f = 0
    if f:
        print("NA")

while 1:
    n = int(input())
    if n == 0:
        break
    a = [list(map(int, input().split())) for _ in range(n)]
    p, q, r, c = map(int, input().split())
    b = [
        x[0]
        for x in a
        if x[1] <= p and x[2] <= q and x[3] <= r and 4 * (x[1] + x[3]) + 9 * x[2] <= c
    ]
    if len(b):
        print(*b, sep="\n")
    else:
        print("NA")

-    n = int(eval(input())) +    n = int(input()) -    a = [[0] * 5 for _ in range(n)] -    for i in range(n): -        a[i][:4] = list(map(int, input().split())) -        a[i][4] = 4 * (sum(a[i][1:4:2])) + 9 * a[i][2] -    p, q, r, c = list(map(int, input().split())) -    f = 1 -    for i in range(n): -        if a[i][1] <= p and a[i][2] <= q and a[i][3] <= r and a[i][4] <= c: -            print((a[i][0])) -            f = 0 -    if f: +    a = [list(map(int, input().split())) for _ in range(n)] +    p, q, r, c = map(int, input().split()) +    b = [ +        x[0] +        for x in a +        if x[1] <= p and x[2] <= q and x[3] <= r and 4 * (x[1] + x[3]) + 9 * x[2] <= c +    ] +    if len(b): +        print(*b, sep="\n") +    else: