#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int d[101][101];
	for(int i=1;i<=100;i++)for(int j=1;j<=100;j++)d[i][j]=10000000;
	int n;
		int a,b,c;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>c;
		for(cin>>a;a>0;a--){
			cin>>b;
			d[c][b]=1;
		}
	}
	/*
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(d[i][j]<1000)cout<<d[i][j]<<" ";
			else cout<<"+ ";
		}
		cout<<endl;
	}
	cout<<endl;
	*/
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				if(j!=k)if(d[j][k]>d[j][i]+d[i][k])d[j][k]=d[j][i]+d[i][k];
			}
		}
	}
	/*
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			
			if(d[i][j]<1000)cout<<d[i][j]<<" ";
			else cout<<"+ ";
		}
		cout<<endl;
	}
	cout<<endl;
	*/
	for(cin>>n;n>0;n--){
		cin>>a>>b>>c;
		if(d[a][b]<c)cout<<d[a][b]+1<<endl;
		else cout<<"NA"<<endl;
		
	}
	
	return 0;
}
