#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
const int INF = 10000000;
int wf[101][101];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			wf[i][j] = i == j ? 0 : INF;
		}
	}
	for(int i = 0; i < n; i++) {
		int a, t;
		cin >> a >> t;
		while(t--) {
			int b;
			cin >> b;
			wf[a][b] = 1;
		}
	}

	for(int k = 1; k <= n; k++)
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
				wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);

	int q;
	cin >> q;
	while(q--) {
		int s, d, v;
		cin >> s >> d >> v;
		if(wf[s][d] >= v) {
			cout << "NA" << endl;
		}
		else {
			cout << wf[s][d] + 1 << endl;
		}
	}
}