#include<iostream>
#include<queue>

using namespace std;

int main(){

  int n;
    cin >> n;
    
    int data[n+1][n+1];
    
    for(int i = 0; i <= n; i++){
      for(int j = 0; j <= n; j++){
	data[i][j] = 0;
      }
    }
    
    int from, to, conesum;

    for(int i = 0; i < n; i++){
      cin >> from >> conesum;
      for(int j = 0; j < conesum; j++){
	cin >> to;
	data[from][to] = 1;
      }
    }


    int sumpake;
    cin >> sumpake;

    queue<int> Q;

    int ttl, myposi, min, sumin, sumina, finish = 0;

    for(int i = 0; i < sumpake; i++){
      min = 0;
      cin >> from >> to >> ttl;
      myposi = from;
      for(int j = 0; j < ttl; j++){
	if(j != 0){
	  for(int l = 0; l < sumina; l++){
	    if(Q.front() == to){
	      min = j;
	      finish = 1;
	      break;
	    }
	    myposi = Q.front();
	    Q.pop();
	    for(int k = 1; k <= n; k++){
	      if(data[myposi][k] == 1) {
		Q.push(k);
		sumin++;
	      }
	    }
	    
	  }
	  if(finish == 1) break;
	}else{
	  sumin = 0;
	  for(int k = 1; k <= n; k++){
	    if(data[myposi][k] == 1) {
	      Q.push(k);
	      sumin++;
	    }
	  }
	  
	}
	  sumina = sumin;
	  sumin = 0;
      }
      
      if(min == 0) cout << "NA";
      else cout << min+1;
      cout << endl;
      finish = 0;
      while(!Q.empty()) Q.pop();
    }

  return 0;
}