#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int N=101;

int net[N][N];

int bfs(int n,int s,int d){
  vector<int> time(n);
  queue<int> que;
  rep(i,n)time[i]=INF;
  time[s]=0;
  que.push(s);
  int u;
  while(!que.empty()){
    u=que.front(),que.pop();
    rep(i,n){
      if(time[i]>time[u]+net[u][i]){
        time[i]=time[u]+net[u][i];
        que.push(i);
      }
    }
  }
  return time[d];
}

signed main(){
  int n;
  cin>>n;
  rep(i,n)rep(j,n)net[i][j]=INF;
  rep(i,n){
    int r,k;
    cin>>r>>k;
    r--;
    rep(i,k){
      int t;
      cin>>t;
      t--;
      net[r][t]=1;
    }
  }

  int p;
  cin>>p;
  rep(i,p){
    int s,d,v;
    cin>>s>>d>>v;
    s--;d--;
    int ans=bfs(n,s,d)+1;

    if(ans<=v)cout<<ans<<endl;
    else cout<<"NA"<<endl;
  }
 return 0;
}