#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

// 隣接リスト -> min{s, t}
int dijkstra( vector< vector<PII> > graph, const int start, const int goal )
{
	vector<int> distance( graph.size() );
	fill( ALL( distance ), INT_MAX );

	priority_queue< PII, vector< PII >, greater< PII > > que; // 累計コスト, ノード番号
	que.push( MP( 0, start ) );

	while ( !que.empty() )
	{
		int total = que.top().fst;
		int node = que.top().snd;
		que.pop();

		if ( total < distance[ node ] )
		{
			distance[ node ] = total;

			REP( i, 0, graph[ node ].size() )
			{
				int to = graph[ node ][i].fst;
				int cost = graph[ node ][i].snd;

				que.push( MP( total + cost, to ) );
			}
		}
	}

	return distance[ goal ];
}

int main()
{
	int n;
	cin >> n;

	vector< vector< PII > > graph( n );

	REP( dn, 0, n )
	{
		int r, k;
		cin >> r >> k;
		r--;

		REP( dk, 0, k )
		{
			int t;
			cin >> t;
			t--;

			graph[r].PB( MP( t, 1 ) );
		}
	}

	int p;
	cin >> p;

	REP( dp, 0, p )
	{
		int s, d, v;
		cin >> s >> d >> v;
		s--;
		d--;

		int res = dijkstra( graph, s, d ) + 1;

		if ( res <= v )
		{
			cout << res << endl;
		}
		else
		{
			cout << "NA" << endl;
		}
	}		

	return 0;
}