#include<iostream>
#include<queue>
using namespace std;
#define SUB 103
int net[SUB][SUB],n,maxx=0;
typedef pair<int,int> BVB;
int ans(int,int,int);
int main(){
  int i,j,p,num,n1,th;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> num >> n1;
    if(num >= maxx)maxx = num;
    for(j=0;j<n1;j++){
      cin >> th;
      net[num][th]=1;
    }
  }
  for(int m=0;m<maxx;m++){
    for(int n=0;n<maxx;n++){
      if(net[m][n]!=1)net[m][n]=0;
    }
  }
  int pkn;
  cin >> pkn;
  int st,ed,c,answer;
  for(i=0;i<pkn;i++){
    cin >> st >> ed >> c;
    answer = ans(st,ed,c);
    if(answer != -2)cout << answer << endl;
    else cout << "NA" << endl;
  }
}
int ans(int st,int ed,int c){
  queue<BVB> Nari;
  int i,j,k,l,cal=0,mem=0;
  BVB next,fr;
  fr.first=st;
  fr.second=c;
  Nari.push(fr);
  if(st == ed && c != 0)return 1;
  while(1){
    next=Nari.front();
    Nari.pop();
    next.second=next.second-1;
    if(fr.second == (next.second+1) && next.second == 0 && next.first != ed)return -2;
    if(next.second < 0)break; 
    for(i=1;i<=maxx;i++){
      if(net[next.first][i] == 1)mem++;  
      if(net[next.first][i] == 1 && i == ed ){
	return (fr.second - next.second)+1;
      }
      if(net[next.first][i] == 1)Nari.push(BVB(i,next.second));
      if(mem == n)break;
    }
  }
  return -2;  
}