#include<stdio.h>
int main(void)
{
    int n,a,i[1010];
    int p[1010],q[1010],r[1010],c[1010];
	int pc,qc,rc,cc;
	int f;
	while (scanf("%d",&n),n!=0){
	    for (a=0;a<n;a++){
		    scanf("%d %d %d %d",&i[a],&p[a],&q[a],&r[a]);
			c[a]=4*p[a]+9*q[a]+4*r[a];
		}
		scanf("%d %d %d %d",&pc,&qc,&rc,&cc);
		f=0;
		for (a=0;a<n;a++){
		    if (pc>=p[a]&&qc>=q[a]&&rc>=r[a]&&cc>=c[a]){
			    printf("%d\n",i[a]);
			    f=1;
			}
		}
		if (f==0){
		    printf("NA\n");
		}
	}
	return 0;
}