#include <iostream>
using namespace std;

int main(){
	int n,i,j,k,a,b,c,cost[101][101];
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a>>b;
		for(j=1;j<=n;j++) cost[a][j] = 1<<15;
		for(j=0;j<b;j++){
			cin >> c;
			cost[a][c]=1;
		}
	}
	for(k=1;k<=n;k++)for(i=1;i<=n;i++)for(j=1;j<=n;j++)
		cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a>>b>>c;
		if(cost[a][b]<c && cost[a][b]<(1<<15)) cout << cost[a][b]+1 << endl;
		else cout << "NA" << endl;
	}
}