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

vector <int> ro[101],dis;
queue <int> Q;
int n,s,d,v;
int r,kk;

void reset() {
  dis.resize(n);
  for(int i=0;i<n;i++) 
    dis[i] = 100000000;
}


int bfs() {
  Q.push(s);
  dis[s] = 1;
  int t,a;
  while(!Q.empty()) {
    t = Q.front();
    Q.pop();
   
    for(int i=0;i<ro[t].size();i++) {
      a = ro[t][i];
      if(dis[a] > dis[t]+1 ){
	dis[a] = dis[t]+1;
	if(dis[t]+1 < v && a != d) Q.push(a);
      }
    }
  }
  return dis[d];
}

int main() {
  
  cin >> n;
  int a;
  for(int i=0;i<n;i++) {
    cin >> r >> kk;
    ro[r-1].resize(kk);
    for(int j=0;j<kk;j++) {
      cin >> a;
      ro[r-1][j] = a - 1;
    }
  }
  
  int p;
  int ans;
  cin >> p;
  for(int i=0;i<p;i++) {
    cin >> s >> d >> v;
    s--;
    d--;
    reset();
    ans = bfs();
    if(ans <= v) cout << ans << endl;
    else cout <<"NA" << endl;
    
  }
  
  return 0;
  

}