#define _GLIBCXX_DEBUG
 
#include <bits/stdc++.h>
 
using namespace std;

class Dijkstra {
#define MAX_V 102
  typedef pair<int, int> P;

private:
  const int INF = 1e9 + 10;
  struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) { }
  };

  int V;
  vector<Edge> G[MAX_V];

public:

  Dijkstra(int V): V(V) { 
    if (V >= MAX_V) {
      assert(false);
    }
  }

  void AddEdge(int from, int to, int cost) {
    G[from].push_back(Edge(to, cost));
  }

  vector<int> Solve(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    vector<int> d(V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
      P p = que.top(); que.pop();
      int v = p.second;
      if (d[v] < p.first) {
        continue;
      }
      for (int i = 0; i < G[v].size(); i++) {
        Edge e = G[v][i];
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(P(d[e.to], e.to));
        }
      }
    }

    return d;
  }
};


int main() {
  int n;
  cin >> n;
  Dijkstra dijkstra(101);
  
  for (int i = 0; i < n; i++) {
    int r, k;
    cin >> r >> k;
    for (int j = 0; j < k; j++) {
      int t;
      cin >> t;
      dijkstra.AddEdge(r, t, 1);
    }
  }

  int p;
  cin >> p;

  for (int i = 0; i < p; i++) {
    int s, d, v;
    cin >> s >> d >> v;
    vector<int> dists = dijkstra.Solve(s);
    int dist = dists[d];
    if (dist >= v) {
      cout << "NA" << endl;
    } else {
      cout << dist + 1 << endl;
    }
  }
  
  
  return 0;
}