#include <iostream>
#include <queue>
#define N 100
#define INFINITY 2000000000
using namespace std;
int bfs();
int n,r,k,t,p,s,g,v,u,M[N][N],d[N],result;
string color[N];
int main(){
  int i,j;
  cin >> n;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    cin >> r >> k;
    for(j=0;j<k;j++){
      cin >> t;
      M[r-1][t-1]=1;
    }
  }
  cin >> p;
  for(i=0;i<p;i++){
    cin >> s >> g >> v;
    s--,g--;
    result=bfs();
    if(result!=0) cout << result << endl;
    else cout << "NA" << endl;
  }
  return 0;
}
int bfs(){
  int i,j;
  queue<int> q;
  for(i=0;i<n;i++) color[i]="WHITE",d[i]=INFINITY;
  color[s]="GLAY";
  d[s]=0;
  q.push(s);
  while(q.empty()!=1){
    u=q.front();
    q.pop();
    for(i=0;i<n;i++){
      if(M[u][i]&&color[i]=="WHITE"){
	color[i]="GLAY";
	d[i]=d[u]+1;
	q.push(i);
      }
    }
    color[u]="BLACK";
  }
  v-=d[g];
  if(v>0) return d[g]+1;
  return 0;
}