#include<iostream>
#include<queue>
using namespace std;

#define MAX_N 110

#define INF 999999999

int x[MAX_N][MAX_N];
int d[MAX_N];

queue<int>Q;

int bfs(int s, int t){
	for(int i=0;i<MAX_N;i++){
		d[i]=INF;
	}
	d[s]=0;
	Q.push(s);
	while(!Q.empty()){
		int z=Q.front();
		for(int i=0;i<MAX_N;i++){
			if(x[z][i]<INF){
				if(d[i]==INF){
					d[i]=d[z]+1;
					Q.push(i);
				}
			}
		}
		Q.pop();
	}
	return d[t];
}

int main(){
	int n,m,a,b,c;
	for(int i=0;i<MAX_N;i++){
		for(int j=0;j<MAX_N;j++){
			x[i][j]=INF;
		}
	}
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		for(int j=0;j<b;j++){
			cin>>c;
			x[a][c]=1;
		}
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>a>>b>>c;
		int y=bfs(a,b);
		if(y>=c){cout<<"NA"<<endl;}
		else{cout<<y+1<<endl;}
	}
	return 0;
}