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

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

void visit(int sn,int dis) {
  int x;

  //  for(int i=1;i<=n;i++)cout << flg[i];
  // cout <<" ";
  
  flg[sn+1] = 1;
  
  if(sn == d-1 && dis <=v)  md = min(md,dis);

  else if(dis <= v && dis < md) {
    for(int i=0;i<ro[sn].size();i++) {
      
      if(flg[ro[sn][i]] == 0){
	//	cout <<sn+1 << "to"<<ro[sn][i] << endl;
	visit(ro[sn][i]-1,dis+1);
	flg[ro[sn][i]] = 0;
      }
    } 
  }
}
  
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++) flg[i] = 0;
    md = 10000000;
   
    visit(s-1,1);
    if(md != 10000000) cout << md <<endl;
    else cout << "NA" <<endl;
  }
  
  return 0;
  
}