#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int g[n][n];
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			g[i][j] = 100000000;
	int r,k,t;
	for(int i = 0; i < n; i++){
		cin >> r >> k;
		r--;
		for(int j = 0; j < k; j++){
			cin >> t;
			t--;
			g[r][t] = 1;
		}
	}
	int p;
	cin >> p;
	for(int i = 0; i < p; i++){
		int s,d,v;
		cin >> s >> d >> v;
		s--; d--;
		vector <int> used(n,false);
		vector <int> dist(n,100000000);
		dist[s] = false;
		while(1){
			int va = -1;
			for(int j = 0; j < n; j++){
				if(used[j] == false && (va == -1 || dist[va] > dist[j]))
					va = j;
			}
			if(va == -1)
				break;
			used[va] = true;
			for(int j = 0; j < n; j++)
				dist[j] = min(dist[j] , dist[va] + g[va][j]);	
		}

		if(v > dist[d])
			cout << dist[d] + 1 << endl;
		else
			cout << "NA" << endl;
	}
	return 0;
}