#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	vector<int> a[100];
	int b[100];
	bool l[100];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int r, k, t;
		cin >> r >> k;
		r--;
		for (int j = 0; j < k; j++) {
			cin >> t;
			t--;
			a[r].push_back(t);
		}
		sort(a[r].begin(), a[r].end());
	}
	int p;
	cin >> p;
	for (int i = 0; i < p; i++) {
		int s, d, v;
		cin >> s >> d >> v;
		s--;
		d--;
		fill(b, b + n, 100000);
		b[s] = 0;
		fill(l, l + n, false);
		l[s] = true;
		int sum = 0;
		multimap<int, int> m;
		for (int j = 0; j < a[s].size(); j++) {
			m.insert(map<int, int>::value_type(1, a[s][j]));
		}
		multimap<int, int>::iterator it = m.begin();
		while (!l[d]) {
			it = m.begin();
			sum=(*it).first+1;
			if (sum > v) break;
			int e = (*it).second;
			m.erase(it);
			for (int j = 0; j < a[e].size(); j++) {
				l[a[e][j]] = true;
				b[a[e][j]] = min(b[a[e][j]],sum);
			}
		}
		if (l[d]) {
			cout << b[d] << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
}