#include<iostream>
#include<set>
#include<cstring>
#include<algorithm>

using namespace std;

int CntData[101][101];
const int INF = 1000000;

void Init() {
	for (int i = 1; i < 101; i++) {
		for (int j = 1; j < 101; j++) {
			CntData[i][j] = INF;
		}
	}
}

void solve(int n) {
	for (int k = 1; k < n; k++) {
		for (int i = 1; i < n; i++) {
			for (int j = 1; j < n; j++) {
				CntData[i][j] = min(CntData[i][j], CntData[i][k] + CntData[k][j]);
			}
		}
	}
}

int main() {
	int n, p, r, k, t;

	Init();
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> r >> k;
		for (int j = 0; j < k; j++) {
			cin >> t;
			CntData[r][t] = 1;
		}
	}
	solve(n+1);
	
	cin >> p;
	while (p--) {
		cin >> r >> k >> t;
		if (t > CntData[r][k]) {
			cout << CntData[r][k]+1 << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}

	return 0;
}


