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

int main(){
  int a,b,c,d,e,f,g,now,v[101],m[101][101]={};
  queue<int> q;
  cin >> a;
  for(int i=1;i<=a;i++){
    cin >>b>>c;
    for(int j=0;j<c;j++){
      cin >> d;
      m[i][d]=1;
    }
  }
  cin >> d;
  for(int i=0;i<d;i++){
    cin >> e >> f >> g;
    q.push(e);
    for(int j=1;j<=a;j++)v[j]=1200;
    v[e]=1;
    while(1){
      now=q.front();q.pop();
      if(now==f){
	if(v[f]>g){
	  cout << "NA" << endl;
	  break;
	  }else {
	  cout << v[now] << endl;
	  break;
	}
      }
      for(int j=1;j<=a;j++){
	if(m[now][j]==1&&v[j]==1200){
	  v[j]=v[now]+1;
	  q.push(j);
	}
      }
      if(q.empty()){
	cout<< "NA" << endl;
	break;
      }
    }
    while(!q.empty())q.pop();
  }
  return 0;
}