#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;

const int INF = 1000000000;

int n;
vector<int> way[128];

int mini(int s, int d, int v);

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		int r, k;
		
		scanf("%d %d", &r, &k);
		while (k-- > 0){
			int t;
			
			scanf("%d", &t);
			way[r].push_back(t);
		}
	}
	
	int p;
	
	scanf("%d", &p);
	while (p-- > 0){
		int s, d, v;
		
		scanf("%d %d %d", &s, &d, &v);
		int cost = mini(s, d, v);
		if (cost == INF) puts("NA");
		else printf("%d\n", cost);
	}
	
	return 0;
}

int mini(int s, int d, int v)
{
	int diff[128];
	queue<P> q;
	
	fill(diff, diff + n + 1, INF);
	q.push(P(s, 1));
	diff[s] = 1;
	while (!q.empty()){
		P p = q.front(); q.pop();
		
		if (diff[p.first] < p.second) continue;
		for (int i = 0; i < way[p.first].size(); i++){
			int tmp = way[p.first][i];
			
			if (diff[tmp] > diff[p.first] + 1){
				diff[tmp] = diff[p.first] + 1;
				q.push(P(tmp, diff[tmp]));
			}
		}
	}
	
	if (diff[d] == INF || diff[d] > v) return INF;
	else return diff[d];
}