#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

struct edge{ 
	int to, cost;
	edge(int to, int cost) :to(to), cost(cost){};
};
vector<edge> G[110];

int n, r, k, t;
int p, s, d, v;

int dis[110];

void dijkstra(int start){
	dis[start] = 0;

	priority_queue<P> que;
	que.push(P(0, start));

	while (!que.empty()){
		P p = que.top(); que.pop();
		int a = p.second;

		if (dis[a] < p.first)continue;

		for (int i = 0; i < G[a].size(); i++){
			edge e = G[a][i];
			if (dis[e.to] > dis[a] + e.cost){
				dis[e.to] = dis[a] + e.cost;
				que.push(P(dis[e.to], e.to));
			}

		}
	}
}

int main(){
	cin >> n;
	REP(i, n){
		cin >> r >> k;
		REP(j, k){
			cin >> t;
			G[r].push_back(edge(t, 1));
		}
	}
	cin >> p;
	REP(i, p){
		REP(j, 110)dis[j] = INF;
		cin >> s >> d >> v;
		dijkstra(s);
		if (dis[d] + 1 <= v)cout << dis[d] + 1 << endl;
		else cout << "NA" << endl;
	}
}