#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;
    vector<vector<pii>>edge(n,vector<pii>());
    rep(i,n){
        int r; cin>>r;
        --r;
        int k; cin>>k;
        rep(j,k){
            int to; cin>>to;
            edge[r].push_back(pii(to-1,1));
        }
    }
    int p; cin>>p;
    rep(_,p){
        priority_queue<pii,vector<pii>,greater<pii>>que;
        int from,to,cost; cin>>from>>to>>cost;
        --to,--from;
        vector<int>d(n,INF);
        d[from]=0;
        que.push(pii(0,from));
        while(!que.empty()){
            pii now=que.top(); que.pop();
            if(now.second==to)break;
            if(d[now.second]<now.first)continue;
            for(int i=0; i<edge[now.second].size();i++){
                pii next=edge[now.second][i];
                if(d[next.first]<now.first+next.second)continue;
                d[next.first]=now.first+next.second;
                que.push(pii(now.first+next.second,next.first));
            }
        }
        if(d[to]<cost)cout<<d[to]+1<<endl;
        else cout<<"NA"<<endl;
    }
}