#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int pass[200][200];
int n;

int dijk(int s,int g){
    int d[200];
    bool used[200];
    rep(i,200)d[i]=999999999;
    rep(i,200)used[i]=false;
    d[s]=0;
    
    while(1){
        int v=-1;
        rep(u,n){
            if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
        }
        if(v==-1)break;
        
        used[v]=true;
        
        rep(u,n){
            d[u] = min(d[u],d[v]+pass[v][u]);
        }
    }
    return d[g];
}


int main(){
    while(cin>>n){
        rep(i,200)rep(j,200)pass[i][j]=999999999;
        rep(i,200)pass[i][i]=0;
        rep(i,n){
            int r,k;
            cin>>r>>k;
            r--;
            rep(j,k){
                int x;
                cin>>x;
                x--;
                pass[r][x]=1;
            }
        }
        int p;
        cin>>p;
        rep(i,p){
            int s,g,v;
            cin>>s>>g>>v;
            s--,g--;
            int res = dijk(s,g)+1;
            if(res<=v)cout<<res<<endl;
            else cout<<"NA"<<endl;
        }
    }
}