#include <iostream>
#include <queue>
#include <algorithm>

int main(){
    using namespace std;

    int n, M[101][101] = {};
    cin >> n;
    for(int i = 0; i < n; ++i){
        int num, src;
        cin >> src >> num;
        for(int j = 0; j < num; ++j){
            int dest;
            cin >> dest;
            M[src][dest] = 1;
        }
    }
    int m;
    cin >> m;
    for(int i = 0; i < m; ++i){
        int src, dest, ttl, d[n + 1];
        fill(d, d + n + 1, -1);

        cin >> src >> dest >> ttl;
        d[src] = 1;
        queue<int> q;
        q.push(src);
        while(!q.empty()){
            int const u = q.front();
            q.pop();
            for(int v = 1; v < n + 1; ++v){
                if(M[u][v] == 1 && d[v] == -1){
                    d[v] = d[u] + 1;
                    q.push(v);
                }
            }
        }
        if(ttl - d[dest] >= 0){
            cout << d[dest];
        }else{
            cout << "NA";
        }
        cout << endl;
    }
}