#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;n++)
int n,nn, a, b, c;

int main() {
	cin >> n;
	int data[n+1][n+1];
	for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= n; ++j) {
				data[i][j]=900000;
			}
	}
	for (int i = 0; i < n; ++i) {
		cin >> a>>b;
		for (int j = 0; j < b; ++j) {
			cin >> c;
			data[a][c]=1;
		}
	}


	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			for (int k = 1; k <= n; ++k) {
				data[j][k]=min(data[j][k],data[j][i]+data[i][k]);
			}
		}
	}
	/*for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= n; ++j) {
				cout<<i<<" "<<j<<" "<<data[i][j]+1<<endl;
			}
	}*/


	cin>>n;
	for (int i = 0; i < n; ++i) {
		cin>>a>>b>>c;
		if(data[a][b]+1<=c){cout<<data[a][b]+1<<endl;}
		else{cout<<"NA"<<endl;}
	}
return 0;

}