#include<iostream>
#include<vector>
using namespace std;
enum{I,P,Q,R,C};
int main()
{
  int n;
  int limit[5];
  while(cin>>n,n){
    vector< vector<int> >food(n,vector<int>(5,0));
    for(int i=0;i<n;i++){
      for(int j=0;j<4;j++)cin>>food[i][j];
      food[i][C] = 4*food[i][P] + 9*food[i][Q] + 4*food[i][R];
    }

    for(int j=1;j<=4;j++)cin>>limit[j];

    int count=0;
    for(int i=0;i<n;i++){
      bool ok=true;
      for(int j=1;j<=4;j++)if(food[i][j]>limit[j])ok=false;
      if(!ok)continue;
      cout<<food[i][I]<<endl;
      count++;
    }
    if(!count)puts("NA");
  }
}