#include <iostream>
#include <sstream>
#include <algorithm>

#define INF 1000000000

using namespace std;

int main(void){
	int n;
	int s, t, num;
	
	cin >> n;
	int d[n][n];
	fill((int *)d, (int *)d+n*n, INF);
	//for(int i=0;i<n;i++) d[i][i] = 0;
	for(int i=0;i<n;i++){
		cin >> s;
		cin >> num;
		for(int j=0;j<num;j++){
			cin >> t;
			d[s-1][t-1] = 1;
		}
	}
	
	//WF
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	
	cin >> n;
	
	for(int i=0;i<n;i++){
		cin >> s >> t >> num;
		d[s-1][t-1]+1 <= num?cout << d[s-1][t-1]+1 << endl:cout << "NA" << endl;
	}
}