#include<bits/stdc++.h>
using namespace std;

vector<int>rinsetu[100]{};
unordered_map<int, int>taiou;
int main() {
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		int c, d; scanf("%d%d", &c, &d);
		taiou[c] = b;
		for (int e = 0; e < d; e++) {
			int f; scanf("%d", &f);
			rinsetu[b].push_back(f);
		}
	}
	int b; cin >> b;
	for (int c = 0; c < b; c++) {
		int g, h, i; scanf("%d%d%d", &g, &h, &i);
		int e[100]{};
		memset(e, -1, sizeof(e));
		queue<int>Q;
		e[taiou[g]] = 1;
		Q.push(g);
		while (Q.size()) {
			int o = Q.front(); Q.pop();
			o = taiou[o];
			if (e[o] > i)break;
			for (int p : rinsetu[o]) {
				if (e[taiou[p]] == -1) {
				 e[taiou[p]] = e[o] + 1; Q.push(p);
				}
			}
		}
		if (e[taiou[h]] == -1||e[taiou[h]]>i)puts("NA");
		else cout << e[taiou[h]] << endl;
	}
}