#include<iostream>
using namespace std;
 
int main()
{
    int n, s[1001], p[1001], q[1001], r[1001];
 
    while( cin >> n )
    {
        if( n == 0 )
            break;
 
        for( int i = 0; i < n + 1; i++ )
            cin >> s[i] >> p[i] >> q[i] >> r[i];
 
        bool j = false;
        for( int i = 0; i < n; i++ )
        {
            if( p[i] <= s[n] && q[i] <= p[n] && r[i] <= q[n] && p[i] * 4 + q[i] * 9 + r[i] * 4 <= r[n] )
            {
                cout << s[i] << endl;
                j = true;
            }
        }
        if( j == false )
            cout << "NA" << endl;
    }
 
    return 0;
}
