#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
using namespace std;
#define SUB 101

int net[SUB][SUB],n;

typedef pair<int,int> BVB;


int ans(int,int,int);

void debug();

int main(){

  for(int k=0;k<SUB;k++)for(int l=0;l<SUB;l++)net[k][l]=-1; //Syokika

  int i,j,p,num,n1,th;

  cin >> n;

  for(i=0;i<n;i++){ //net's info
    
    cin >> num >> n1;



    for(int k=0;k<SUB;k++)net[num][k]=0;    //siyoukanou

    for(j=0;j<n1;j++){
      cin >> th;
      net[num][th]=1;
    }

  }//net's info

  int pkn;

  cin >> pkn;

  int st,ed,c,answer;

  // debug();



  for(i=0;i<pkn;i++){//pack's info
    cin >> st >> ed >> c;


    answer = ans(st,ed,c);

    if(answer != -2)cout << answer << endl;
    else cout << "NA" << endl;

  }//pack's info



}



//L[(ÊÌzñÅà¢¢¯Ç)ÉÇñÇñüêÄ¢«TTLªO¢ÉÈéOÉÚInÉBÅ«é©Ç¤©ð²×é
//[^ÍÚInÉBµ½n_ÌTTL©çvZµÄ¾·
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);
  /*
  cout << "FIRST next.second = " << c << endl;  
  cout << "FIRST cal = " << cal << endl;
  */  

  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; //I¹ð
    //cout << "next.second = " << next.second << endl; 
    
    for(i=1;i<=SUB;i++){//¢¯éêðL[Éüêé
      if(net[next.first][i] == 1)mem++;  

    
      
      if(net[next.first][i] == 1 && i == ed ){ //ÚInB
	/*	
	cout << "GOOOOOOOOOL!!! i = " << i <<endl;
	cout << "             cal = " << cal << endl;
	cout << "     next.second = " << next.second << endl; 
	*/

	return (fr.second - next.second)+1;
	
      }
      
      if(net[next.first][i] == 1)Nari.push(BVB(i,next.second));
      
      if(mem == n)break;
    }
      
    
  }

  return -2;
  
  
  
}










void debug(){
  for(int i=1;i<=10;i++){
    if(i==1){
      cout << "   ";
      for(int k=1;k<=10;k++){
	printf("%3d",k);
      }
      cout << endl;
      for(int k=1;k<=10;k++)printf("___");
      cout << endl;
    }

    for(int j=1;j<=10;j++){
      if(j == 1)cout << i << " |";
      printf("%3d",net[i][j]);
    }
    cout << endl;

  }



}