#include<stdio.h>
int main(void)
{
	int n,i,a[1000],s[1000],d[1000],f[10000],g,h,j,k,w[1000],flg;
	while(1){
	scanf("%d",&n);
	if(n==0) break;
	for(i=0;i<n;i++){
	scanf("%d %d %d %d",&a[i],&s[i],&d[i],&f[i]);
	w[i]=4*s[i]+9*d[i]+4*f[i];
	}
	scanf("%d %d %d %d",&g,&h,&j,&k);
		flg=0;
	for(i=0;i<n;i++){
	if(s[i]<=g&&d[i]<=h&&f[i]<=j&&w[i]<=k){
		printf("%d\n",a[i]);
		flg=1;
		}
	}
	if(flg==0){
		printf("NA\n");
		}
	}
return 0;
}