#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main()
{
	int d[101][101];
	const int Inf = 100000000;
	for (int i = 1; i < 101; ++i)
		for (int j = 1; j < 101; ++j)
			d[i][j] = Inf;
	for (int i = 1; i < 101; ++i)
		d[i][i] = 0;

	int n;
	scanf("%d", &n);
	while (n--)
	{
		int no, m;
		scanf("%d %d", &no, &m);
		while (m--)
		{
			int t;
			scanf("%d", &t);
			d[no][t] = 1;
		}
	}
	for (int k = 1; k < 101; ++k)
		for (int i = 1; i < 101; ++i)
			for (int j = 1; j < 101; ++j)
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

	int p;
	scanf("%d", &p);
	while (p--)
	{
		int src, dest, ttl;
		scanf("%d %d %d", &src, &dest, &ttl);
		int r = d[src][dest] + 1;
		if (ttl >= r)
			printf("%d\n", r);
		else
			puts("NA");
	}

	return 0;
}