#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;
#define M 100000000

// ツパツケツッツトツつェツ経ツ由ツつキツづゥツδ仰ーツタツづ個催短ツ仰猟猟」ツづーツダツイツクツスツトツδ可づ仰づ淞づゥツ。
// ttl >= ツ個仰嘉環づ按づァ ツ個仰嘉環づーツ陛板つキ
// ttl < ツ個仰嘉環づ按づァ -1 ツづーツ陛板つキ
int dijkstra (int from ,int to, vector <vector <int> > t )
{
	int size = t.size();
	vector <int> d (size, M );
	vector <bool> v (size, false );
	int i,p;

	d[from] = 1;

	int mind = M;

	do{
		mind = M;
		for (i = 1; i < size; ++i){
			if (!v[i] && mind > d[i] ){
				mind = d[i];
				p = i;
			} // end if
		} // end for
		
		v[p] = true;

		for (i = 1; i < size; ++i){
			if ( d[p] + t[p][i] < d[i] ){
				d[i] = d[p] + t[p][i];
			} // end if
		} // end for
	} while (mind != M );
	

	return d[to];
}
	
int main()
{
//	cut here before submit 
//	freopen ("testcase.packet", "r", stdin );
	string str = "";
	string res = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;

	vector <vector <int> > t (n+1, vector <int> (n+1, M) );
	vector <vector <int> > memo (n+1, vector <int> (n+1, M ) );
	int i,j;
	for (i = 0; i < n; ++i){
		int from, num, to;
		getline (cin, str );
		stringstream ss(str);

		ss >> from >> num;
		for (j = 0; j < num; ++j){
			ss >> to;
			t[from][to] = 1;
		} // end for
	} // end for
	

	for (i = 1; i <= n; ++i){
		for (j = 1; j <= n; ++j){
			if (i != j ){
				memo[i][j] = dijkstra (i, j, t );
			} // end if
		}  // end for
	} // end for


	int p;
	getline (cin, str );
	stringstream ssp (str );
	ssp >> p;
	
	for (i = 0; i < p; ++i){
		int from, to , ttl;
		getline (cin, str );
		stringstream ss (str );
		ss >> from >> to >> ttl;
	
		int res = -1;
		if (memo[from][to] <= ttl ){
			res = memo[from][to];
		}else{
			res = -1;
		} // end if		

		if (res == -1){
			cout << "NA" << endl;
		}else{
			cout << res << endl;
		} // end if
	} // end for

	return 0;
}