#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;
typedef pair<int, int> P;
static const int INF = 99999999;
struct SEdge
{
	int To;
	int Cost;
};
vector<int> d;
vector< vector<SEdge> > G;

void Dijkstra(int s)
{
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P> > PQue;
	PQue.push(P(0, s));
	while(!PQue.empty())
	{
		P p = PQue.top();
		PQue.pop();
		int v = p.second;
		if(d[v] < p.first)
		{
			continue;
		}
		for(int i = 0; i < G[v].size(); ++i)
		{
			SEdge e = G[v][i];
			if(d[e.To] > d[v] + e.Cost)
			{
				d[e.To] = d[v] + e.Cost;
				PQue.push(P(d[e.To], e.To));
			}
		}
	}
}

void solve()
{
	int n;
	cin >> n;
	d.resize(n);
	G.resize(n);
	for(int i = 0; i < n; ++i)
	{
		int From, To_Size;
		cin >> From >> To_Size;
		--From;
		vector<int> Vec(To_Size);
		for(int j = 0; j < To_Size; ++j)
		{
			cin >> Vec[j];
			--Vec[j];
			SEdge e;
			e.To = Vec[j];
			e.Cost = 1;
			G[From].push_back(e);
		}
	}
	int p;
	cin >> p;
	for(int i = 0; i < p; ++i)
	{
		int s, g, vp;
		cin >> s >> g >> vp;
		--s;
		--g;
		Dijkstra(s);
		if(d[g] + 1 <= vp)
		{
			cout << d[g] + 1 << endl;
		}
		else
		{
			cout << "NA" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}