#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define INF 10000000
using namespace std;
typedef pair<int,int> p;
vector<int> V[101];
int cost[101];

void dijkstra(int s,int d,int v1) {
  priority_queue<p,vector<p>, greater<p> > que;
  for(int i=0;i<101;i++) {
    cost[i] = INF;
  }
  cost[s] = 1;
  que.push(p(0,s));

  while(!que.empty()) {
    p v = que.top();que.pop();
    int P = v.second;
    if(cost[P] < v.first) continue;
    for(unsigned int i=0;i<V[P].size();i++) {
      int to = V[P][i];
      if(cost[to] > cost[P] + 1) {
        cost[to] = cost[P] + 1;
        que.push(p(cost[to],to));
      }
    }
  }
  if(v1 - cost[d] >= 0)
    cout << cost[d] << endl;
  else
    cout << "NA" << endl;
}

int main() {
  int n,t,k,r,p,s,d,v;
  string str;
  while(cin >> n) {

    for(int i=0;i<n;i++) {
      cin >> r >> k;
      for(int j=0;j<k;j++) {
        cin >> t;
        V[r].push_back(t);
      }
    }

    cin >> p;
    for(int i=0;i<p;i++) {
      cin >> s >> d >> v;
      dijkstra(s,d,v);
    }
  }
}