#include <iostream>
#include <queue>
#include <array>

int main() {
  static int const MaxElement = 100;
  std::array<std::array<bool, MaxElement>, MaxElement> map = {};

  int n = 0;
  std::cin >> n;
  for( int i=0; i<n; ++i ) {
	int r = 0, k = 0;
	std::cin >> r >> k;
	for( int j=0; j<k; ++j ) {
	  int idx = 0;
	  std::cin >> idx;
	  map[r-1][idx-1] = true;
	}
  }

  int m = 0;
  std::cin >> m;
  for( int i=0; i<m; ++i ) {
	int src = 0, dst = 0, ttl = 0;
	std::cin >> src >> dst >> ttl;

	std::array<int, MaxElement> distance;
	distance.fill( -1 );

	std::queue<int> q;
	q.push( src - 1 );
	distance[src-1] = 0;
	while( !q.empty() ) {
	  int const u = q.front();
	  q.pop();
	  for( int v=0; v<n; ++v ) {
		if ( map[u][v] && distance[v] == -1 ) {
		  distance[v] = distance[u] + 1;
		  q.push( v );
		}
	  }
	}

	if ( distance[dst-1] == -1 || ttl - distance[dst-1] <= 0 ) {
	  std::cout << "NA" << std::endl;
	} else {
	  std::cout <<  distance[dst-1] + 1 << std::endl;
	}
  }
}