#include <cstdio>

int n,s[1001],p[1001],q[1001],r[1001],c[1001];

int main(){
	while(scanf("%d",&n),n != 0){
		for(int i = 0; i < n; i++){
			scanf("%d%d%d%d",&s[i],&p[i],&q[i],&r[i]);
			c[i] = (p[i] + r[i]) * 4 + q[i] * 9;
		}
		scanf("%d%d%d%d",&p[n],&q[n],&r[n],&c[n]);
		bool t = false;
		for(int i = 0; i < n; i++){
			if(p[i] <= p[n] && q[i] <= q[n] && r[i] <= r[n] && c[i] <= c[n]){
				printf("%d\n",s[i]);
				t = true;
			}
		}
		if(!t) printf("NA\n");
	}

	return 0;
}