#include <iostream>
#include <queue>
#include <vector>

using namespace std;

vector<int> hyou[110];

int hyou2[110];

int bfs(int s, int d) {
	queue<int> q;
	q.push(s);
	int k;
	hyou2[s] = 0;
	while (!q.empty()) {
		k = q.front();
		q.pop();
		for (int i = 0; i < hyou[k].size(); i++) {
			int t = hyou[k][i];
			if (hyou2[t] != -1) {
			} else {
				hyou2[t] = hyou2[k]+1;
				if (t == d) {
					return hyou2[t];
				}
				q.push(t);
			}
		}
	}
	return 0;
}

int main() {
	int n;
	cin >> n;
	int a, b, c;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		for (int j = 0; j < b; j++) {
			cin >> c;
			hyou[a].push_back(c);
		}
	}
	int k;
	int p, q, r;
	cin >> k;
	for (int i = 0; i < k; i++) {
		cin >> p >> q >> r;
		for (int j = 0; j <= n; j++) {
			hyou2[j] = -1;
		}
		int g = bfs(p, q);
		if (g != 0 && r > g) {
			cout << g+1 << endl;
		} else {
			cout << "NA" << endl;
		}
	}
	return 0;
}