#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<numeric>
#define INF 1e+8
#define EPS 1e-9
#define PB push_back
#define fi first
#define se second
#define reps(i,j,k) for(int i = j; i < k; i++)
#define rep(i,j) reps(i,0,j)
using namespace std;
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
typedef long long ll;
typedef pair<int,int> Pii;
int D[128][128];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,128)rep(j,128)D[i][j] = INF;
	rep(i,n){
		int index;
		scanf("%d",&index);
		int sub;
		scanf("%d",&sub);
		rep(j,sub){
			int tmp;
			scanf("%d",&tmp);
			D[index][tmp] = 1;
		}
	}
	rep(k,101){
		rep(i,101){
			rep(j,101){
				D[i][j] = min(D[i][j],D[i][k]+D[k][j]);
			}
		}
	}
	int m;
	scanf("%d",&m);
	rep(i,m){
		int a,b,cost;
		scanf("%d%d%d",&a,&b,&cost);
		if(D[a][b]+1 <= cost )printf("%d\n",D[a][b]+1);
		else puts("NA");
	}
	return 0;
}