#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    int n,p;
    int map[101][101];
    memset(map,10000,sizeof(map));
    cin >> n;
    REP(i,n){
	int r,k,t;
	cin >> r >> k;
	REP(j,k){
	    cin >> t;
	    map[r][t] = 1;
	}
    }
    n++;
    while(true){
	bool flg = false;
	REP(k,n){
	    REP(i,n){
		REP(j,n){
		    if(map[i][j] > (map[i][k] + map[k][j])){
			flg = true;
			map[i][j] = map[i][k] + map[k][j];
		    }
		}
	    }
	}
	if(!flg) break;
    }

    cin >> p;
    REP(a,p){
	int s,d,v;
	cin >> s >> d >> v;
	if(map[s][d] < v) cout << map[s][d]+1 << endl;
	else cout << "NA" << endl;
    }
    return 0;
}