#include <bits/stdc++.h>

using namespace std;

// 1 to 0-indexed
vector<int> G[100];

typedef pair<int, int> Pii;
typedef pair<int, Pii> Piii;

int bfs(int S, int T, int TTL) {
  
  int memo[100];
  memset(memo, -1, sizeof(memo));
  memo[S] = 0;
  queue<Piii> Q;
  Q.push(Piii(0, Pii(S, TTL)));
  while(!Q.empty()) {
    
    Piii piii = Q.front(); Q.pop();
    
    int cost = piii.first;
    int now = piii.second.first;
    int ttl = piii.second.second;
    
    if(now == T) return cost;
    if(memo[now] < cost) continue;

    if(ttl <= 1) continue;
    
    for(int i=0; i<G[now].size(); i++) {
      int to = G[now][i];
      if(memo[to] == -1) {
	memo[to] = cost + 1;
	Q.push(Piii(cost+1, Pii(to, ttl-1)));
      }
    }
  }
  
  return -1;
}

int main() {
  
  int N;
  while(cin >> N) {
    
    for(int i=0; i<100; i++) G[i].clear();
    
    for(int i=0; i<N; i++) {
      int r; cin >> r; r--;
      int k; cin >> k;
      for(int i=0; i<k; i++) {
	int x; cin >> x; x--;
	G[r].push_back(x);
      }
    }
    
    int Q; cin >> Q;
    while(Q--) {
      int s, t, v;
      cin >> s >> t >> v; s--, t--;
      int res = bfs(s, t, v);
      if(res >= 0) {
	cout << res+1 << endl;
      }
      else {
	cout << "NA" << endl;
      }
    }
    
  }
  
  return 0;
}