#include<iostream>
using namespace std;

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      int i[n],p[n],q[n],r[n];
      for(int j=0;j<n;j++)
	cin>>i[j]>>p[j]>>q[j]>>r[j];
      int pp,qq,rr,cc;
      cin>>pp>>qq>>rr>>cc;
      bool flag=true;
      for(int j=0;j<n;j++)
	{
	  //	  cout<<p[j]<<" "<<q[j]<<" "<<r[j]<<" "<<p[j]*4+q[j]*4+r[j]*9<<endl;
	  if(p[j]<=pp &&q[j]<=qq &&r[j]<=rr &&p[j]*4+q[j]*9+r[j]*4<=cc)
	    {
	    cout<<i[j]<<endl;
	    flag=false;
	    }
	}
      if(flag)
	cout<<"NA"<<endl;

    }

}