#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef pair<int,int> NODE;

map<int,vector<int> > list;

int bfs(int s,int g){
	map<int,bool> done;
	queue< NODE > Q;
	Q.push( make_pair(s,1) );
	while(!Q.empty()){
		NODE q = Q.front();
		Q.pop();
		done[q.first] = true;
		
		if(q.first == g){
			return q.second;
		}
		for(int i=0;i<list[q.first].size();i++){
			if( !done[ list[q.first][i] ] )Q.push( make_pair(list[q.first][i],q.second+1) );
		}
	}
	cout << endl;
	return (1<<21);
}
int main(){
	int n,r,k,t;
	int p,s,d,v;
	cin >> n;
	list.clear();
	for(int i=0;i<n;i++){
		cin >> r >> k;
		for(int j=0;j<k;j++){
			cin >> t;
			list[r].push_back(t);
		}
	}
	cin >> p;
	for(int i=0;i<n;i++){
		cin >> s >> d >> v;
		int ret = bfs(s,d);
		if( ret <= v){
			cout << ret << endl; 
		}else{
			cout << "NA" << endl;
		}
	}
}