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

#define INFTY 2000000000

int n,u,k;
int s,d,v,TTL;
int M[101][101],D[101];

void bfs( int s ){
  
  queue <int> Q;
  for( int i = 1; i <= n; i++ ) D[i] = INFTY;

  D[s] = 1;
  Q.push(s);
     
  while( !Q.empty() ){
    u = Q.front(); Q.pop();
    for( int l = 1; l <= n; l++ ){
      if( M[u][l] == 0 ) continue;
      if( D[l] != INFTY ) continue;
      D[l] = D[u] + 1;
      // cout << "l" << " " << l << " " <<  "D[l]" << " " << D[l] << " " <<
      // 	"D[u]" << " " << D[u] << endl;
      Q.push(l);

      if ( D[l] > TTL ){
	cout << "NA" << endl;
	return;
      }else if( l == d ){
	cout << D[l] << endl;
	//	cout << "TTL" << " " << TTL << endl;
	return;
      }

    }

  }
 
}

int main(){
  cin >> n;
  for( int i = 1; i <= n; i++ ){
    cin >> u;
    cin >> k;
    for( int j = 0; j < k; j++ ){
      int v;
      cin >> v;
      M[u][v] = 1;
    }
  }
    
  int p; cin >> p; 
  for( int i = 0; i < p; i++ ){
  cin >> s >> d >> TTL;
  bfs(s);
  }

  return 0;
}