#include <iostream>
#include <list>
#include <queue>
#include <set>

using namespace std;

int solve( list<int> *router, int from, int to, int ttl ){
	set<int> history;
	queue<int> q;
	int dist[101];

	for( int i = 0;i < 101;i++ ) dist[i] = 9999999;

	history.insert( from );
	q.push( from );
	dist[from] = 1;

	while( !q.empty() ){
		int u = q.front();

		if( dist[u] > ttl ){
			q.pop();
			continue;
		}

		if( u == to ){
			return dist[u];
		}

		for( list<int>::iterator it = router[u].begin(); it != router[u].end(); it++ ){
			int v = *it;
			if( history.count( v ) ) continue;
			history.insert( v );
			dist[v] = dist[u] + 1;
			q.push( v );
		}
		q.pop();
	}
	return -1;
}



int main(void)
{
	int n;
	list<int> router[101];

	cin >> n;

	for( int i = 0;i < n;i++ ){
		int hoge;
		int number;
		int piyo;

		cin >> number >> hoge;

		for( int j = 0;j < hoge;j++ ){
			cin >> piyo;
			router[number].push_back( piyo );
		}
	}

	cin >> n;
	int from,to,ttl;
	for( int i = 0;i < n;i++ ){
		cin >> from >> to >> ttl;
		int answer = solve( router, from, to, ttl );
		if( answer == -1 ) cout << "NA" << endl;
		else cout << answer << endl;
	}
	return 0;
}