#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

const int inf = 1<<24;
const int size = 101;
int n, p;
int CN[size][size];
int CNcnt[size];
int MC[size];

typedef pair <int, int> Node;
typedef priority_queue <Node, vector <Node>, greater <Node> > QUEUE;

void dijkstra( int start, int goal, int ttl ) {
    QUEUE Q;
    Node start_node( 1, start );
    MC[start] = 1;
    Q.push( start_node );

    while ( !Q.empty() ) {
        Node node = Q.top();
        Q.pop();

        int router = node.second;
        int cost = node.first;

        if ( router == goal ) {
            cout << cost << endl;
            return;
        }

        for ( int i = 0; i < CNcnt[router]; i++ ) {
            int next_router = CN[router][i] - 1;
            int next_cost = cost + 1;
            
            if ( next_cost >= ttl + 1 ) continue;
            if ( next_cost >= MC[next_router] ) continue;
            MC[next_router] = next_cost;
            Node next_node( next_cost, next_router );
            Q.push( next_node );
        }
    }

    cout << "NA" << endl;
}

void init() {
    for ( int i = 0; i < size; i++ ) {
        MC[i] = inf;
    }
}

void solve() {
    cin >> p;
    for ( int i = 0; i < p; i++ ) {
        int start, goal, ttl;
        cin >> start >> goal >> ttl;
        init();
        dijkstra( start-1, goal-1, ttl );
    }
}

void input() {
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        int r, k;
        cin >> r >> k;
        CNcnt[r-1] = k;
        for ( int j = 0; j < k; j++ ) {
            cin >> CN[r-1][j];
        }
    }
}

int main( void ) {
    input();
    solve();
    return 0;
}