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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int N, P;
int d[100][100];

int main(){
    std::cin >> N;

    REP(i, 100){
        REP(j, 100){
            if(i == j){d[i][j] = 0;}
            else{d[i][j] = INF;}
        }
    }

    REP(i, N){
        int from, k;
        std::cin >> from >> k;
        --from;
        
        REP(j, k){
            int to;
            std::cin >> to;
            --to;
            
            d[from][to] = 1;
        }
    }

    REP(k, N){
        REP(i, N){
            REP(j, N){
                d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    std::cin >> P;
    REP(i, P){
        int s, t, ttl;
        std::cin >> s >> t >> ttl;
        --s; --t;

        if(d[s][t] == INF || d[s][t] >= ttl){
            puts("NA");
        }else{
            printf("%d\n", d[s][t] + 1);
        }
    }
}