#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
struct data{
	int n,p,q,r,c;
};
int main(){
	int n;
	while(cin >> n,n){
		data a[1001] = {};
		for(int i = 0; i < n; i++){
			int n,p,q,r;
			scanf("%d%d%d%d",&n,&p,&q,&r);
			data d = {n,p,q,r,(p*4+q*9+r*4)};
			a[i] = d;
		}
		int P,Q,R,C;
		scanf("%d%d%d%d",&P,&Q,&R,&C);
		bool flg = false;
		for(int i = 0; i < n; i++){
			if(P >= a[i].p && Q >= a[i].q && R >= a[i].r && C >= a[i].c){
				flg = true;
				printf("%d\n",a[i].n);
			}
		}
		if(!flg)puts("NA");
	}

	return 0;
}