#include <iostream>
#include <algorithm>
using namespace std;

const int INF = 1000000;
int edge[100][100];

void WF(int n){
	for(int k = 0;k < n;++k){
		for(int i = 0;i < n;++i){
			for(int j = 0;j < n;++j){
				if(i == j) continue;
				edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
			}
		}
	}
}

int main(){
	int n, p, r, k, t, a;
	for(int i = 0;i < 100;++i){
		for(int j = 0;j < 100;++j){
			edge[i][j] = INF;
		}
	}
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> r >> k;
		--r;
		for(int j = 0;j < k;++j){
			cin >> a;
			--a;
			edge[r][a] = 1;
		}
	}
	WF(n);
	cin >> p;
	for(int i = 0;i < p;++i){
		int s, d, v;
		cin >> s >> d >> v;
		--s;
		--d;
		if(edge[s][d] + 1 <= v) cout << edge[s][d] + 1 << endl;
		else cout << "NA" << endl;
	}
	return 0;
}