#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<bits//stdc++.h>
#include<functional>
using namespace std;
struct P{
	int cost,pos;
};
bool operator<(P a,P b) {return a.cost<b.cost;}
bool operator>(P a,P b) {return a.cost>b.cost;}
long long a[101];
const long long inf=800000000;
vector<long long>e[101];
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int r,k,c;
		cin>>r>>k;
		for(int i=0;i<k;i++){
			cin>>c;
			e[r].push_back(c);
		}
	}
	int p;
	cin>>p;
	for(int z=0;z<p;z++){
		int s,d,v;
		cin>>s>>d>>v;
		fill(a,a+n+1,inf);
		priority_queue<P>p;
		p.push(P{1,s});
		a[s]=1;
		while(!p.empty()){
			P t=p.top();p.pop();
			for(int i=0;i<(int)e[t.pos].size();i++){
				if(a[t.pos]+1<a[e[t.pos][i]]){
					a[e[t.pos][i]]=a[t.pos]+1;
					p.push(P{a[t.pos]+1,e[t.pos][i]});
				}
			}
		}
		if(a[d]<=v) cout<<a[d]<<endl;
		else cout<<"NA"<<endl;
	}
}