#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
typedef long long ll;

int d[110][110];

int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            d[i][j] = INF;
        }
        d[i][i] = 0;
    }
    for (int i = 0; i < n; i++) {
        int r, k;
        cin >> r >> k;
        --r;
        int t;
        for (int j = 0; j < k; j++) {
            cin >> t;
            d[r][t-1] = 1;
        }
    }
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    int p;
    cin >> p;
    for (int i = 0; i < p; i++) {
        int s, D, v;
        cin >> s >> D >> v;
        if (v > d[s-1][D-1]) {
            cout << d[s-1][D-1]+1 << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return 0;
}