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

int i, j, n, r, k, t, p, s, _d, v, ans;
int dic(int d[][100]) {
  int mi = s, f[100] = {};
  vector <int> cost(100, 100000000);
  cost[s] = 0; //テ・ツ、ツァテ、ツコツ?
  for(i = 0; i < n; i++) {
    f[mi] = 1;
    for(j = 0; j < n; j++)  if(d[mi][j] == 1 && !f[j] && cost[j] > cost[mi] + 1) cost[j] = cost[mi] + 1;
    int min = 200000000;
    for(j = 0; j < n; j++)  if(!f[j] && min > cost[j]) min = cost[mi = j];
  }
  return cost[_d];
}    

int main() {
  while(cin >> n) {
    int d[100][100] = {};
    for(i = 0; i < n; i++) {//
      cin >> r >> k;
      r--;
      while(k--) {
	cin >> t;
	t--;
	d[r][t] = 1;
      }
    }
    cin >> p;
    while(p--) {
      cin >> s >> _d >> v;
      s--; _d--;
      ans = dic(d) + 1;
      if(ans <= v)  cout << ans << endl;
      else cout << "NA" << endl;
    }
  }
  return 0;
}
    