#include<iostream>
#include<vector>
#include<algorithm>
#define M 10000

using namespace std;

bool TransportPacket(const vector< vector<int> >& data,
		     int s, int g, int ttl, int* ans_){
  vector<bool> is_reached(data.size(), false);
  vector<int> ans(data.size(), M);
  int i, j;
  ans[s] = 0;
  i = s;
  while(i != g){
    is_reached[i] = true;
    for(j=0; j<data[i].size(); ++j){
      ans[j] = min(ans[j], ans[i] + data[i][j]);
    }
    for(i=-1, j=0; j<is_reached.size(); ++j){
      if(!is_reached[j] && (i < 0 || ans[i] > ans[j])) i = j;
    }
  }
  *ans_ = ans[g] + 1;
  if(ttl - *ans_ >= 0) return true;
  else return false;
}

int main(){
  int n, r, k, t;
  int s, d, v, ans;

  cin >> n;
  vector< vector<int> > data(n, vector<int>(n, M));

  for(int i=0; i<n; ++i){
    cin >> r >> k;
    for(int j=0; j<k; ++j){
      cin >> t;
      data[r-1][t-1] = 1;
    }
  }
  cin >> n;
  for(int i=0; i<n; ++i){
    cin >> s >> d >> v;
    if(TransportPacket(data, s-1, d-1, v, &ans)) cout << ans << endl;
    else cout << "NA" << endl;
  }
  return 0;
}