#include<stdio.h>
#include<limits.h>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;

const int N = 108;
bool isConnect[N][N];

int MinRoot(int from,int to,int rootNum)
{
	int distance[N],i;
	fill(distance,distance+N,INT_MAX);
	queue<pair<int,int> > q;
	pair<int,int> p;
	q.push(make_pair(from,1));
	while(!q.empty())
	{
		p=q.front(); q.pop();
		if(distance[p.first] <= p.second) continue;

		distance[p.first] = p.second;

		for(i=1; i<=rootNum; ++i)
		{
			if(isConnect[p.first][i])
			{
				q.push(make_pair(i,p.second+1));
			}
		}
	}
	return distance[to];
}
int main()
{
	int n,connectCount,fromRooterNum,toRooterNum,i,j,p,ttl;

	for(i=0;i<N;++i) for(j=0;j<N;++j) isConnect[i][j] = false;

	scanf("%d",&n);
	for(i=0; i<n; ++i)
	{
		scanf("%d%d",&fromRooterNum,&connectCount);
		for(j=0; j<connectCount; ++j)
			scanf("%d",&toRooterNum),isConnect[fromRooterNum][toRooterNum]=true;
	}
	scanf("%d",&p);
	for(i=0;i<p;++i)
	{
		scanf("%d%d%d",&fromRooterNum,&toRooterNum,&ttl);
		int minRooter = MinRoot(fromRooterNum,toRooterNum,n);
		if(minRooter>ttl) puts("NA");
		else printf("%d\n",minRooter);
	}
	return 0;
}