#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int a[n+1][5],p=0;
    r(i,n+1){
      cin>>a[i][0]>>a[i][1]>>a[i][2]>>a[i][3];
      a[i][4]=a[i][1]*4+a[i][2]*9+a[i][3]*4;
    }
    r(i,n){
      if(a[i][1]<=a[n][0]&&a[i][2]<=a[n][1]&&a[i][3]<=a[n][2]&&a[i][4]<=a[n][3])
        {cout<<a[i][0]<<endl;p++;}
    }
    if(!p)cout<<"NA"<<endl;
  }
}