#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int md = 10000000;
vector <int> ro[100];
int s,d,v;
int s2,d2;
int kk[100],n;
bool flg[101] ;

void visit(int sn,int dis) {
  int x;
  
  flg[sn] = 1;
  
  if(sn == d2 && dis <=v){
    md = min(md,dis);
  }
  
  else if(dis <= v) {
    for(int i=0;i<ro[sn].size();i++) {
      for(int j=0;j<n;j++)
	if(ro[sn][i] == kk[j]) {
	  x = j;
	  break;
	}
      if(dis == 1){
	for(int i=0;i<=n;i++) flg[i] = 0;
	//	cout <<"reset"<<endl;
	flg[s2] = 1;
      }
      //       cout <<sn+1 << "to"<<x+1 << endl;
      if(flg[x] == 0) visit(x,dis+1);
    } 
  }
}
  
int main() {

  cin >> n;
  int a;
    
  for(int i=0;i<n;i++) {
    cin >> kk[i];
    cin >> a;
    ro[i].resize(a);
    for(int j=0;j<a;j++) cin >> ro[i][j];
  }
  
  int p;
  cin >> p;
  for(int i=0;i<p;i++) {
    cin >> s >> d >> v;

   
    for(int i=0;i<n;i++){
      if(kk[i] == s) s2 = i;
      if(kk[i] == d) d2 = i;
    }

    for(int i=0;i<=n;i++) flg[i] = 0;
    md = 10000000;
   
    visit(s2,1);
    if(md != 10000000) cout << md <<endl;
    else cout << "NA" <<endl;
  }
  
  return 0;
  
}