#include<iostream>
using namespace std;
int a, b, c, d, e[500000][5], n, cnt;
int main() {
	while (true) {
		cin >> n; cnt = 0; if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> e[i][0] >> e[i][1] >> e[i][2] >> e[i][3];
			e[i][4] = e[i][1] * 4 + e[i][2] * 9 + e[i][3] * 4;
		}
		cin >> a >> b >> c >> d;
		for (int i = 0; i < n; i++){
			if (a >= e[i][1] && b >= e[i][2] && c >= e[i][3] && d >= e[i][4]) {
				cout << e[i][0] << endl; cnt++;
			}
		}
		if (cnt == 0) { cout << "NA" << endl; }
	}
}