#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<utility>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define all(v) v.begin(),v.end()
using namespace std;

const double eps = 1e-8;
const double INF = 1e12;

int cal(int p,int q,int r){
	return (p+r)*4+q*9;
}

int main(){
	int n;
	while(cin>>n,n){
		int dt[n],p[n],q[n],r[n];
		rep(i,n){
			cin>>dt[i]>>p[i]>>q[i]>>r[i];
		}
		int rp,rq,rr,rc;
		cin>>rp>>rq>>rr>>rc;
		int cnt=0;
		rep(i,n){
			if(rp>=p[i] && rq>=q[i] && rr>=r[i] && rc>=cal(p[i],q[i],r[i])){
				cout<<dt[i]<<endl;
				cnt++;
			}
		}
		if(cnt==0)cout<<"NA"<<endl;

	}
	return 0;
}