#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	bool y[105][105] = {};


	int n; cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a,b; cin >> a>>b;
		for (int j = 0; j < b; j++) {
			int z;
			cin >> z;
			y[a][z] = 1;
		}
	}
	
	int p; cin >> p;
	for (int i = 0; i < p; i++) {
		int s, d, t;
		cin >> s >> d >> t;
		queue<int>Q;
		Q.push(s);
		int h = 1;
		int R[105] = {};
		for (int j = 0; j <= 102; j++)
			R[j] = 999999;
		R[s] = 1;
		while (Q.size()) {
			int v = Q.front();
			h = R[v];
			h++;
		
			
			bool F[105] = {};
			for (int j = 1; j <= n; j++) {
				if (y[v][j] && R[j] > h) {
					R[j] = h;
					Q.push(j);
				}



			}
			Q.pop();	
		}
/*		for (int j = 0; j < n; j++)
			cout << R[j] << " ";*/
		if (R[d] <= t)cout << R[d] << endl;
		else cout << "NA" << endl;
	}
	
	return 0;

}