#include <cstdio>
#include <algorithm>
using namespace std;
int id[1001];
int p[1001], q[1001], r[1001], kcal[1001];

int main() {
    int n, P, Q, R, C, sum;
    for (; ; ) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i < n; i++) {
            scanf("%d %d %d %d", &id[i], &p[i], &q[i], &r[i]);
            kcal[i] = p[i]*4+q[i]*9+r[i]*4;
        }
        scanf("%d %d %d %d", &P, &Q, &R, &C);
        sum = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] <= P && q[i] <= Q && r[i] <= R && kcal[i] <= C) { printf("%d\n", id[i]); sum++; }
        }
        if (!sum) printf("NA\n");
    }

    return 0;
}

