#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
 



const int MAX_V = 100;
 
int d[MAX_V][MAX_V];
int V;
  
void warshall_floyd_init(){
    for(int i = 0; i < V; i++){
        for(int j = 0; j < V; j++){
            if(i == j) d[i][i] = 0;
            else d[i][j] = INF;
        }
    }
}
 
void warshall_floyd() {
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}



 int main(){
 	cin>>V;
 	warshall_floyd_init();
 	int r, k, t;
 	for(int i = 0; i < V; i++){
 		cin>>r>>k;
 		r--;
 		for(int j = 0; j < k; j++){
 			cin>>t;
 			t--;
 			d[r][t] = 1;
 		}
 	}
 	warshall_floyd();

 	int p;
 	cin>>p;
 	for(int i = 0; i < p; i++){
 		cin>>r>>k>>t;
 		r--; k--;
 		if(d[r][k] < t){
 			cout<<d[r][k] + 1<<endl;
 		}
 		else cout<<"NA"<<endl;
 	}
 }