#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <cmath>
#include <string.h>
#include <set>


using namespace std;



int main(){
    int n;
    while(cin>>n){
        int graph[101][101]={0};
        for(int roop=0; roop<n; roop++){
            int r;
            cin>>r;
            int k;
            cin>>k;
            for(int roop2=0; roop2<k; roop2++){
                int t;
                cin>>t;
                graph[r][t]=1;
            }
        }
        
        int q;
        cin>>q;
        for(int roop=0; roop<q; roop++){
            int s,d,v;
            cin>>s>>d>>v;
            int visit[101]={0};
            visit[s]=1;
            queue<pair<int,int>> qu;
            pair<int,int> now;
            now.first=s;
            now.second=v;
            qu.push(now);
            bool find=false;
            
            
            while(!qu.empty()){
                
                now=qu.front();
                //cout<<now.first<<" "<<now.second<<endl;
                qu.pop();
                if(now.first==d){
                    find=true;
                    break;
                }
                if(now.second>1){
                    for(int i=1; i<=n; i++){
                        if(graph[now.first][i]==1&&visit[i]==0){
                            visit[i]=1;
                            pair<int,int> temp;
                            temp.first=i;
                            temp.second=now.second-1;
                            qu.push(temp);
                        }
                    }
                }
            }
            if(find)cout<<v-now.second+1<<endl;
            else cout<<"NA"<<endl;
            
        }
    }
}