#include <iostream>
#include <vector>
#include <queue>
#include <climits>
#define REP(i,n) for(int i=0;i<n;++i)

//ダイグスとらで解くそうです

using namespace std;

typedef pair<int,int> DisNum;

vector<int> canto;

int Serch(vector<DisNum> canConnect[102],int from,int to,int hp)
{
	if(from == to)
		return -1;
	int distance[102] = {};//距離を保存
	REP(i,102) distance[i] = INT_MAX;
	priority_queue<DisNum,vector<DisNum>,greater<DisNum> > qu;//行き先のストックをキュー
	qu.push(DisNum(0,from));
	distance[from] = 0;
	while(!qu.empty())
	{
		DisNum nowfrom;
		nowfrom = qu.top();qu.pop();
		if(distance[nowfrom.second] != nowfrom.first) continue;
		if(nowfrom.second == to) return nowfrom.first;
		for(int i=0;i<canConnect[nowfrom.second].size();++i)
		{
			int v = canConnect[nowfrom.second][i].second;//今から調べる先の座標
			int n = nowfrom.second;
			if(distance[v] > distance[n] + canConnect[nowfrom.second][i].first)
			{
				distance[v] = distance[n] + canConnect[nowfrom.second][i].first;
				qu.push(DisNum(distance[v],v));
			}
		}
	}
}

int main(void)
{
	int maxn;
	canto.clear();
	vector<DisNum> canConnect[102];
	cin >> maxn;
	for(int i=0;i<maxn;++i)
	{
		int r,k;
		cin >> r >> k;
		for(int j=0;j<k;++j)
		{
			int t;
			cin >> t;
			canConnect[r].push_back(DisNum(1,t));
		}
	}
	int l;
	cin >> l;
	for(int j=0;j<l;++j)
	{
		int s,d,v;
		cin >> s >> d >> v;
		int ans = Serch(canConnect,s,d,v) + 1;
		if(ans <= v)
			cout << ans << endl;
		else
			cout << "NA" << endl;
	}
	return 0;
}