#include <iostream>
#include <vector>
#include <map>
using namespace std;

struct food{
	int p,q,r,id;
	food(int p_, int q_, int r_, int id_ ){
		p = p_; q = q_; r = r_;	id = id_;
	}
	food(){
		p = q = r = id = 0;
	}
	int cal(){ return p * 4 + q * 9 + r * 4; }
};

int main(){
	int n;
	while( cin >> n, n ){
		vector<food> v;
		for(int i=0 ; i < n ; i++ ){
			int id, p, q, r;
			cin >> id >> p >> q >> r;
			v.push_back( food(p,q,r,id) );
		}
		int P, Q, R, C;
		cin >> P >> Q >> R >> C;
		bool flag = false;
		for(int i=0 ; i < v.size() ; i++ ){
			if( v[i].p <= P && v[i].q <= Q && v[i].r <= R && v[i].cal() <= C ){
				flag = true;
				cout << v[i].id << endl;
			}
		}
		if( !flag ){
			cout << "NA" << endl;
		}
	}
}