#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 long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;

#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

typedef vector<char> VC;
typedef vector< VC > VVC;

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

	VVI res( n, VI( n, INT_MAX / 10 ) );

	REP( i, 0, n )
	{
		int from, num;
		cin >> from >> num;

		from--;

		REP( j, 0, num )
		{
			int to;
			cin >> to;

			to--;

			res[ from ][ to ] = 1;
		}
	}

	const int N = res.size();

	REP( k, 0, N )
	{
		REP( i, 0, N )
		{
			REP( j, 0, N )
			{
				res[i][j] = min( res[i][j], res[i][k] + res[k][j] );
			}
		}
	}

	int p;
	cin >> p;

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

		s--;
		d--;

		int dist = res[s][d] + 1;

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

	return 0;
}