#include <stdio.h>

#define MAX 1000

int main(void){
	int n;
	int id[MAX], p[MAX], q[MAX], r[MAX], c[MAX];
	int pLim, qLim, rLim, cLim;
	int valids;
	
	while (scanf("%d", &n), n){
		valids = 0;
		for (int i=0; i<n; i++){
			scanf("%d %d %d %d", &id[i], &p[i], &q[i], &r[i]);
			c[i] = p[i]*4 + q[i]*9 + r[i]*4;
		}
		scanf("%d %d %d %d", &pLim, &qLim, &rLim, &cLim);
		for (int i=0; i<n; i++){
			if (p[i] > pLim) continue;
			if (q[i] > qLim) continue;
			if (r[i] > rLim) continue;
			if (c[i] > cLim) continue;
			printf("%d\n", id[i]);
			valids++;
		}
		if (valids==0) puts("NA");
	}
	
	return 0;
}
		