#include<iostream>
#include<algorithm>
#define INF 1e8
using namespace std;

int graf[105][105];

void wfloyd(int V) {
	for (int k = 0;k < V;k++) {
		for (int i = 0;i < V;i++) {
			for (int j = 0;j < V;j++)graf[i][j] = min(graf[i][j], graf[i][k] + graf[k][j]);
		}
	}
}

int main() {
	int n;
	cin >> n;
	
	for (int i = 0;i <= n;i++)
		for (int j = 0;j <= n;j++)graf[i][j] = INF;

	for (int i = 0;i < n;i++) {
		int s, d;
		cin >> s >> d;

		for (int j = 0;j < d;j++) {
			int a;
			cin >> a;
			graf[s-1][a-1] = 1;
		}
	}

	wfloyd(n);
	int p;
	cin >> p;
	for (int i = 0;i < p;i++) {
		int a, b, c;
		cin >> a >> b >> c;
		int d = graf[a-1][b-1];
		if (d >= c)cout << "NA" << endl;
		else cout << d + 1 << endl;
	}
	return 0;
}