#include <iostream>
using namespace std;

int main()
{
    int N;
    int s[1000], p[1000], q[1000], r[1000], c[1000];
    int P, Q, R, C;
    
    while(cin >> N, N){
        
        bool check = false;
        
        for(int i = 0; i < N; i++){
            cin >> s[i] >> p[i] >> q[i] >> r[i];
            c[i] = (4 * p[i]) + (9 * q[i]) + (4 * r[i]);
        }
        
        cin >> P >> Q >> R >> C;
        
        for(int i = 0; i < N; i++){
            if(p[i] <= P && q[i] <= Q && r[i] <= R && c[i] <= C) {
                check = true;
                cout << s[i] << endl;
            }
        }
        
        if(!check) cout << "NA" << endl;
    }
    
}
