#include <iostream>
#include <vector>
#include <queue>
#include <map>
#define MAX 10000000
using namespace std;

typedef pair<int,int> P;
struct edge{
  int to,cost; edge(){}
  edge(int cost,int to):to(to),cost(cost){}
};
vector< vector<edge> > info(110);
int n,m,co[110],ttl;

void init(){
  for(int i=0;i<110;i++) co[i] = MAX;
}

int Dijkstra(){
  init();
  int s,d;
  cin >> s >> d >> ttl;
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0,s));
  co[s] = 0;
  while(!que.empty()){
    P p = que.top(); que.pop();
    int now = p.second,c = p.first;
    if(now == d) return c + 1;
    for(int i=0;i<info[now].size();i++){
      edge e = info[now][i];
      if(e.cost + c < co[e.to]){
	que.push(P(e.cost + c,e.to));
	co[e.to] = e.cost + c;
      }
    }
  }
  return -1;
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    int r,k,tmp;
    cin >> r >> k;
    for(int j=0;j<k;j++){
      cin >> tmp;
      info[r].push_back(edge(1,tmp));
    }
  }
  cin >> m;
  while(m--){
    int d = Dijkstra();
    if(d > ttl || d == -1) cout << "NA" << endl;
    else cout << d << endl;
  }
}