#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#define int long long
using namespace std;
int a[1001], b[1001], c[1001], d[1001], test[1001];
signed main() {
    int n, p, q, r, s, P, Q, R, C;
    for (int z = 0; z < 100; z++) {
        int x = 0;
        cin >> n; if (n == 0) { return 0; }
        for (int h = 0; h < n; h++) {
            cin >> s >> p >> q >> r;
            a[h] = s; b[h] = p; c[h] = q; d[h] = r;
            test[h] = 4 * p + 9 * q + 4 * r;
        }
        cin >> P >> Q >> R >> C;
        for (int h = 0; h < n; h++) {
            if (b[h] <= P && c[h] <= Q && d[h] <= R && test[h] <= C) {
                cout << a[h] << endl; x++;
            }
        }
        if (x == 0) { cout << "NA" << endl; }
    }
}
