#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<set>

using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

int main(){
  int n;
	cin>>n;
	int graph[n][n];
	for(int j=0;j<n;j++)
		for(int i=0;i<n;i++){
			if(i==j)
				graph[j][i] = 1;
			else
				graph[j][i] = 1000;
		}
	for(int i=0;i<n;i++){
		int k,m,l;
		cin>>k>>m;
		for(int j=0;j<m;j++){
			cin>>l;
			graph[k-1][l-1] = 1;
		}
	}
	
	for(int j = 0;j<n;j++)
		for(int i = 0;i<n;i++)
			for(int k=0;k<n;k++)
				if(graph[i][j]>graph[i][k]+graph[k][j])
					graph[i][j] = graph[i][k]+graph[k][j];
	int p;
	cin>>p;
	for(int i=0;i<p;i++){
		int s,d,v;
		cin>>s>>d>>v;
		if(graph[s-1][d-1]<v)
			cout<<graph[s-1][d-1]+1<<endl;
		else
			cout<<"NA"<<endl;
	}
  return 0;
}