#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it = (c).begin(); it != (c).end(); it++)
#define X first
#define Y second
#define IND first
#define Z second.first
#define V second.second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int N = 101;

bool ok[N][N];
bool visited[N];
int n, res, vv;

int main(void){
    cin >> n;

    rep(i, n){
        int r, k; cin >> r >> k;
        while(k--){
            int t; cin >> t;
            ok[r][t] = true;
        }
    }

    int p; cin >> p;
    while(p--){
        int s, d; cin >> s >> d >> vv;
        res = INF;
        COUNT(i, N) visited[i] = false;

        queue< pair<int, pii> > q;
        q.push(mp(s, mp(d, vv - 1)));

        while(!q.empty()){
            pair<int, pii> cur = q.front();
            q.pop();

            if(cur.IND == cur.Z){
                res = vv - cur.V;
                break;
            }
            if(!cur.V || visited[cur.IND]) continue;
            visited[cur.IND] = true;

            COUNT(i, N)
                if(ok[cur.IND][i]){
                    pair<int, pii> next = mp(i, mp(cur.Z, cur.V - 1));
                    q.push(next);
                }
        }
     
        if(res == INF) cout << "NA" << endl;
        else cout << res << endl;
    }

    return 0;
}