#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

#define rep(i,a,n) for(ll i = a;i < n;i++)

signed main(){
    ll n,s[1000] = {},p[1000] = {},q[1000] = {},r[1000] = {},cal_memo;
    ll P,Q,R,C;
    bool flag = false;
    
    
    while(1){
        flag = false;
        cin >> n;
        if(!n) break;
        
        
        rep(i,0,n){
            cin >> s[i] >> p[i] >> q[i] >> r[i];
        }
        
        cin >> P >> Q >> R >> C;
        
        rep(i,0,n){
            cal_memo = 4 * p[i] + 9 * q[i] + 4 * r[i];
            
            if(cal_memo <=  C && p[i] <=  P && q[i] <= Q && r[i] <= R){
                cout << s[i] << endl;
                flag = true;
            }
        }
        
        if(!flag) cout << "NA" << endl;
        
        
        
    }
    
    
    return 0;
}
