#include <iostream>
using namespace std;

int main() {

  int n;
  while(1) {
  cin >> n;
  if(n == 0) break;

  int cnt = 0;
  int ans[1001];
    int id[1001],p[1001],q[1001],r[1001];
  for(int i=0;i<n;i++) {
    cin >> id[i] >> p[i] >> q[i]>> r[i];
  }
  int P,Q,R,C;
  cin >> P >> Q>>R>>C;

  int flg = 0;
  for(int i=0;i<n;i++){ 
    int cal = 4*p[i]+9*q[i]+4*r[i];
    if(P<p[i]||Q<q[i]||R<r[i]||C<cal) continue;
    cout << id[i]<<endl;
    flg = 1;
  }
  if(flg == 0) cout << "NA"<<endl;

  }

  return 0;
}