#include <iostream>
#include <queue>
#include <map>
#include <climits>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int,int> NODE;
#define pos first
#define ttl second

map< int,vector<int> > info;
int bfs(int s,int d,int v){
	queue<NODE> Q;
	map<int,bool>done;
	
	Q.push( make_pair(s,v));
	while( !Q.empty() ){
		/* queueツづ個静ヲツ督ェツづ個ノツーツドツづーツ訪ツ姪「ツ催渉づ敖づ可つオツづowツ陛渉青板づ可禿シツづェツ、ツキツδーツつゥツづァツ偲ヲツづィツ渉慊つュ */
		NODE now = Q.front();
		Q.pop();
		done[now.pos] = true;
		if(now.pos == d){
			return now.ttl;
		}
		if(now.ttl-1==0)continue;
		for(int i=0;i<info[now.pos].size();i++){
			if( !done[info[now.pos][i]] ){
				Q.push( make_pair(info[now.pos][i], now.ttl-1) );
			}
		}
	}
	return -1;
}

int main(){
	int n,r,k,t;
	
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> r >> k;
		for(int j=0;j<k;j++){
			cin >> t;
			info[r].push_back(t);
		}
	}	
	
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> r >> k >> t;
		 
		if( ~bfs(r,k,t) )cout << t-bfs(r,k,t)+1 << endl;
		else cout << "NA" << endl;
	}
}