#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

int cost[100][100];
int n;
void wf(){
  rep(k,n)rep(i,n)rep(j,n)cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
}

main(){
  cin>>n;
  rep(i,n)rep(j,n)cost[i][j]=2<<24;

  rep(i,n){
    int r;
    cin>>r;--r;
    int k;
    cin>>k;
    rep(j,k){
      int t;
      cin>>t;t--;
      cost[r][t]=1;
    }
  }
  wf();
  int p;
  cin>>p;
  rep(i,p){
    int s,d,v;
    cin>>s>>d>>v;--s,--d;
    int c=cost[s][d];
    if(c<v)cout<<c+1<<endl;
    else cout<<"NA"<<endl;
  }
}