#include<iostream>
#include<map>
#include<queue>

const int INFTY = 1 << 22;

using namespace std;

class Rooter{
  public:
Rooter(){
  this->cost = INFTY;
  this->done = false;
}
  int cost;
  bool done;
  vector<int> vcon;
};

void BFS( int start, map< int, Rooter > &G ){
  queue< Rooter * > q;

  G[ start ].cost = 1;
  G[ start ].done = true;
  q.push( &G[start] );

  while( !q.empty() ){
    Rooter *r = q.front();
    q.pop();

    for(int i = 0; i < r->vcon.size(); i++){
      if( G[ r->vcon[i]].done ){
	continue;
      }
      G[ r->vcon[i] ].cost = min( G[ r->vcon[i] ].cost , r->cost + 1 );
      q.push( &G[ r->vcon[i] ] );
      G[ r->vcon[i] ].done = true;
    }
  }
}

void ResetGraph( map< int, Rooter > &G, vector<int> &vId ){
  for(int i = 0; i < vId.size(); i++){
    G[ vId[i] ].cost = INFTY;
    G[ vId[i] ].done = false;
  }
}

int main(void){
  int n, p;
  vector< int > vId;
  map< int, Rooter > G;

  cin >> n;
  
  for(int i = 0; i < n; i++){
    int no;
    int cnum;
    Rooter r;

    cin >> no >> cnum;
    vId.push_back( no );
    for(int j = 0; j < cnum; j++){
      int connect;
      cin >> connect;
      r.vcon.push_back( connect );
    }
    G[ no ] = r;
  }

  cin >> p;
  for(int i = 0; i < p; i++){
    int s, d, ttl;

    cin >> s >> d >> ttl;
    ResetGraph( G, vId );
    BFS( s, G );
    if( G[d].cost <= ttl ){
      cout << G[d].cost << '\n';
    }else{
      cout << "NA\n";
    }
  }
  
  return 0;
}