#include <iostream>
using namespace std;

struct S
{
	int i;
	int p;
	int q;
	int r;
	int c;
};

int main(void)
{
	int n;
	S s[1000];
	S max;
	while(1)
	{
		cin >> n;
		if(n == 0)
			return 0;
		for(int i=0;i<n;++i)
		{
			cin >> s[i].i;
			cin >> s[i].p;
			cin >> s[i].q;
			cin >> s[i].r;
			s[i].c = s[i].p*4 + s[i].q*9 + s[i].r*4;
		}
		cin >>max.p >> max.q >> max.r >> max.c;

		bool f = false;
		for(int i=0;i<n;++i)
		{
			if(s[i].p <= max.p && s[i].q <= max.q && s[i].r <= max.r && s[i].c <= max.c)
			{
				cout << s[i].i << endl;
				f = true;
			}
		}
		if(f == false)
			cout << "NA" << endl;
	}
	return 0;
}