#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

#define INF (1 << 30)
#define MAX_E 10000
#define MAX_V 1000

struct edge{
	int from;
	int to;
	int cost;
};

edge es[MAX_E];
int d[MAX_V];
int V, E;// V???????????°???E????????°

// O(VE)??§????????????????????????????????§??????

void shortest_path(int s){
	for(int i = 1; i <= V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	while(true){
		bool update = false;
		for(int i = 0; i < E; i++){
			edge e = es[i];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if(!update){
			break;
		}
	}
}

int main(){
	
	int n, p;
	
	cin >> n;
	
	int from_, num, to_, length;
	
	V = n;
	
	E = 0;
	
	for(int i = 0; i < n; i++){
		cin >> from_ >> num;
		for(int j = 0; j < num; j++){
			cin >> to_;
			es[E].from = from_;
			es[E].to = to_;
			es[E].cost = 1;
			E++;
		}
	}
	
	cin >> p;
	
	for(int i = 0; i < p; i++){
		cin >> from_ >> to_ >> length;
		shortest_path(from_);
		if(d[to_] < length){
			printf("%d\n", d[to_] + 1);
		}else{
			printf("NA\n");
		}
	}
	
	return 0;
}