#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep0(i,n) for(i=0;i<(n);i++)
#define repp(i,m,n) for(int i=(m);i<(n);i++)

#define PUTLINE cout<<__LINE__<<endl;

vector<int> edges[110];
int dis[110];

int main() {
	int n;
	cin>>n;
	int r,k;
	rep(i,n){
		cin>>r>>k;
		while(k--){
			edges[r-1].push_back(in()-1);
		}
	}
	int p;
	cin>>p;
	rep(i,p){
		int s,d,v;
		cin>>s>>d>>v;
		s--;d--;
		rep(j,n)dis[j]=100100100;
		priority_queue<pint,vector<pint>,greater<pint> > que;
		que.push(mp(0,s));
		while(!que.empty()){
			pint v=que.top();
			que.pop();
			if(dis[v.second]<=v.first)continue;
			dis[v.second]=v.first;
			rep(j,edges[v.second].size()){
				que.push(mp(v.first+1,edges[v.second][j]));
			}
		}
		if(dis[d]>=v)cout<<"NA"<<endl;
		else cout<<dis[d]+1<<endl;
	}
	return 0;
}