#include <iostream>
#include <map>
#define INF 1e+9
using namespace std;

int main(){
	int n,p;
	map<int,int> num;
	int cost[101][101];
	cin >> n;
	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= n;j++) cost[i][j] = INF;
		cost[i][i] = 0;
	}
	for(int i = 0;i < n;i++){
		int r,k;
		cin >> r >> k;
		for(int j = 0;j < k;j++){
			int t;
			cin >> t;
			cost[r][t] = 1;
		}
	}
	for(int k = 0;k <= n;k++){
		for(int i = 0;i <= n;i++){
			for(int j = 0;j <= n;j++) cost[i][j] = min(cost[i][j],cost[i][k] + cost[k][j]);
		}
	}
	cin >> p;
	for(int i = 0;i < p;i++){
		int s,d,v;
		cin >> s >> d >> v;
		if(cost[s][d] >= v) cout << "NA" << endl;
		else cout << cost[s][d] + 1 << endl;
	}
	return 0;
}