#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
static const int INF = 1e9;

void solve()
{
	int n;
	cin >> n;
	vector< vector<int> > d(n + 1, vector<int>(n + 1));
	for (int i = 0; i < n + 1; ++i)
	{
		for (int j = 0; j < n + 1; ++j)
		{
			d[i][j] = INF;
		}
	}
	for (int i = 0; i < n; ++i)
	{
		int r, k;
		cin >> r >> k;
		for (int j = 0; j < k; ++j)
		{
			int t;
			cin >> t;
			d[r][t] = 1;
		}
	}
	for (int k = 1; k < n + 1; ++k)
	{
		for (int i = 1; i < n + 1; ++i)
		{
			for (int j = 1; j < n + 1; ++j)
			{
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	int p;
	cin >> p;
	for (int i = 0; i < p; ++i)
	{
		int start, dist, v;
		cin >> start >> dist >> v;
		if (d[start][dist] + 1 <= v)
		{
			cout << d[start][dist] + 1 << endl;
		}
		else
		{
			cout << "NA" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}