#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

const int INF = 1e6;
int main(void){
  int n;
  int cost[100][100];
  REP(i,100)REP(j,100)cost[i][j] = (i!=j)?INF:0;
  cin>>n;
  REP(i,n){
    int r,k;
    cin>>r>>k;
    r--;
    while(k--){
      int t;
      cin>>t;
      t--;
      cost[r][t] = 1;
    }
  }
  int p;
  cin>>p;
  REP(k,n)REP(i,n)REP(j,n)cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
  while(p--){
    int s,d,v;
    cin>>s>>d>>v;
    int c = cost[s-1][d-1];
    c++;
    if(c<=v)cout<<c<<endl;
    else cout<<"NA"<<endl;
  }
  return 0;
}