#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e9
#define rep(i,n) for(int i=0;i<n;i++)
struct edge{int to,cost;};
typedef pair<int,int> P;

int V,n,r,k,t,p,s,d,v,D[1001];
vector<edge> g[1001];

int main(){
	while(cin>>n&&n){
		rep(i,n)g[i].clear();
		rep(i,n){
			cin>>r>>k;
			rep(j,k){
				edge e;
				cin>>t;
				e.to=t;
				e.cost=1;
				g[r].push_back(e);
			}
		}
		cin>>p;
		rep(h,p){
			cin>>s>>d>>v;
			priority_queue<P,vector<P>,greater<P> > q;
			fill(D,D+n+1,INF);
			D[s]=0;
			q.push(P(0,s));
			while(!q.empty()){
				P pp=q.top();q.pop();
				int vv=pp.second;
				if(D[vv]<pp.first)continue;
				rep(j,g[vv].size()){
					edge e=g[vv][j];
					if(D[e.to]>D[vv]+e.cost){
						D[e.to]=D[vv]+e.cost;
						q.push(P(D[e.to],e.to));
					}
				}
			}
			if(D[d]<v)cout<<D[d]+1<<endl;
			else cout<<"NA"<<endl;
		}
	}
}