#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

class Node{
public:
	vector< int > e_to;
	vector< int > e_cost;
	
	bool def;
	int min_cost;
	
	Node(){
		def = false;
		min_cost = -1;
	}
};
bool operator==(const Node& ot1, const Node& ot2){
	return ot1.min_cost == ot2.min_cost;
}
bool operator!=(const Node& ot1, const Node& ot2){
	return !(ot1 == ot2);
}
bool operator<(const Node& ot1, const Node& ot2){
	return ot1.min_cost < ot2.min_cost;
}
bool operator>(const Node& ot1, const Node& ot2){
	return ot1.min_cost > ot2.min_cost;
}
bool operator<=(const Node& ot1, const Node& ot2){
	return !(ot1 > ot2);
}
bool operator>=(const Node& ot1, const Node& ot2){
	return !(ot1 < ot2);
}

class Dijkstra{
	priority_queue< Node, vector< Node >, greater< Node > > que;
	vector< Node > nodes;
	
public:
	void Init(int node_num){
		nodes.resize(node_num);
		for(int i = 0; i < node_num; ++i){
			nodes[i] = Node();
		}
	}
	
	void Put(int id, int to, int cost){
		nodes[id].e_to.push_back(to);
		nodes[id].e_cost.push_back(cost);
	}
	
	int Run(int s, int t){
		
		for(vector< Node >::iterator it = nodes.begin(); it != nodes.end(); ++it){
			it->min_cost = -1;
			it->def = false;
		}
		
		nodes[s].min_cost = 0;
		que.push(nodes[s]);
		
		while(!que.empty()){
			Node def_node = que.top();
			que.pop();
		
			if(def_node.def)continue;
		
			def_node.def = true;
		
			for(int i = 0; i < def_node.e_to.size(); ++i){
				int to = def_node.e_to[i];
				int cost = def_node.min_cost + def_node.e_cost[i];
				
				if(nodes[to].min_cost == -1 || cost < nodes[to].min_cost){
					nodes[to].min_cost = cost;
					que.push(nodes[to]);
				}
			}
		}
		return nodes[t].min_cost;
	}
};


int main(){
	int n, r, k, t, p, s, d, v;
	Dijkstra dijk;
	
	
	cin >> n;
	
	dijk.Init(n);

	for(int i = 0; i < n; ++i){
		cin >> r >> k;
		
		for(int j = 0; j < k; ++j){
			cin >> t;
			dijk.Put(r - 1, t - 1, 1);
		}
	}
	
	cin >> p;
	
	for(int i = 0; i < p; ++i){
		cin >> s >> d >> v;
		
		int res = dijk.Run(s - 1, d - 1);
		
		if(res >= v){
			cout << "NA" << endl;
		}else{
			cout << res + 1 << endl;
		}
	}
	return 0;
}