#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;

int main(){
    int n; cin >>n;
    vector< vector<int> > v(n, vector<int>());
    REP(i, n){
        int s, nn; cin >>s >>nn; s--;
        REP(j, nn){
            int e; cin >>e; e--;
            v[s].push_back(e);
        }
    }

    int c; cin >>c;
    REP(i, c){
        int s, e, t; cin >>s >>e >>t; s--; e--;
        queue<P> open;
        open.push( P(s, t) );
        vector<int> closed(n, -1);

        while(!open.empty()){
            P now = open.front(); open.pop();
            int place = now.first, ttl = now.second;
            if(ttl <= 0 || ttl <= closed[place]) continue;
            closed[place] = ttl;
            int s = v[place].size();
            REP(i, s) open.push( P(v[place][i], ttl - 1) );
        }
        if(closed[e] == -1) cout <<"NA" <<endl;
        else cout <<t - closed[e] + 1 <<endl;
    }
    return 0;
}