#include<iostream>
using namespace std;

int main()
{

	int n;

	while(true){

		int i[1000],p[1000],q[1000],r[1000];

		cin >> n;
		if(n==0)
			break;

		for(int j=0 ;j<n ;j++){

			cin >> i[j] >> p[j] >> q[j] >> r[j];
		}
		int P,Q,R,C;
		int sp=0,sq=0,sr=0;
		int cal[1000];
		int count=0;

		cin >> P >> Q >> R >> C;

		for(int j=0 ;j<n ;j++){
			sp = p[j]*4;
			sq = q[j]*9;
			sr = r[j]*4;
			cal[j] = sp + sq + sr;

			if(P >= p[j] && Q >= q[j] && R >= r[j] && C >= cal[j]){
				count++;
				cout << i[j] << endl;
			}
		}
		if(count == 0)
			cout << "NA" << endl;
	}

	return 0;
}