// AOJ 0144 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0144)
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define rep(i,a) for(int i=0;i<(a);++i)
#define clr(a,v) memset((a),(v),sizeof(a))

typedef std::pair<int, int> P;

const int MAX_N = 100;

int n, p;
std::vector<int> G[MAX_N];
bool used[MAX_N];

int bfs( int s, int d, int tl )
{
	clr( used, false );
	std::queue<P> que;
	que.push( P( s, 1 ) );

	while( !que.empty() )
	{
		P p = que.front(); que.pop();
		int v = p.first, dep = p.second;

		if( used[v] || dep > tl )
			continue;
		if( v == d )
			return dep;

		used[v] = true;

		rep( i, G[v].size() )
		{
			int u = G[v][i];

			if( !used[u] )
				que.push( P( u, dep+1 ) );
		}
	}

	return -1;
}

int main()
{
	scanf( "%d", &n );
	rep( i, n )
	{
		int r, k;
		scanf( "%d%d", &r, &k );
		--r;

		rep( j, k )
		{
			int t;
			scanf( "%d", &t );
			G[r].push_back(t-1);
		}
	}

	scanf( "%d", &p );
	rep( i, p )
	{
		int s, d, v;
		scanf( "%d%d%d", &s, &d, &v );

		int c = bfs( s-1, d-1, v );

		if( ~c )
			printf( "%d\n", c );
		else
			puts("NA");
	}

	return 0;
}