#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    cin>>n;
    int d[200][200];
    rep(i,200){
        rep(j,200){
            if(i==j)d[i][j] = 0;
            else d[i][j] = 1<<20;
        }
    }
    rep(i,n){
        int src,k;
        cin>>src>>k;
        src--;
        rep(j,k){
            int dst;cin>>dst;
            dst--;
            d[src][dst] = 1;
        }
    }

    rep(k,n)rep(i,n)rep(j,n){
        d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
    }

    int p;cin>>p;
    rep(i,p){
        int s, t, ttl;
        cin >> s >> t >> ttl;
        --s; --t;
        if(d[s][t] >= ttl) puts("NA");
        else printf("%d\n", d[s][t] + 1);
    }
}