#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

struct Packet{
	Packet(){}

	Packet(int arg_ttl,int loc){
		ttl = arg_ttl;
		went_num = 1;
		for(int i=0; i < 101; i++)checkTable[i] = 0;
		checkTable[loc] = 1;
		current = loc;
	}

	void set(int loc){
		checkTable[loc] = 1;
		current = loc;
		went_num++;
	}

	int ttl,checkTable[101],went_num,current;
};

int main(){

	int n,r,k,to,table[101][101],num_of_packet,start,goal,t_limit,memo[101][101];
	Packet tmp;

	for(int i=1; i <= n; i++){
		for(int k=1; k <= n; k++){
			table[i][k] = 0;
			memo[i][k] = 0;
		}
	}

	scanf("%d",&n);

	for(int i = 0; i < n; i++){
		scanf("%d %d",&r,&k);
		for(int p=0;p < k; p++){
			scanf("%d",&to);
			table[r][to] = 1;
		}
	}

	scanf("%d",&num_of_packet);

	queue<Packet> Q;
	bool FLG;

	for(int i=0; i < num_of_packet; i++){
		scanf("%d %d %d",&start,&goal,&t_limit);

		FLG = false;

		if(memo[start][goal] != 0){
			if(memo[start][goal] <= t_limit){
				printf("%d\n",memo[start][goal]);
			}else{
				printf("NA\n");
			}
			continue;
		}

		for(int i = 1; i <= n; i++){
			if(i != start && table[start][i] == 1){
				if(memo[i][goal] > 0 && memo[i][goal] < t_limit){
					printf("%d\n",memo[i][goal]+1);
					memo[start][goal] = memo[i][goal]+1;
					FLG = true;
					break;
				}
				Packet p(t_limit-1,start);
				p.set(i);
				Q.push(p);
			}
		}



		while(!Q.empty() && FLG == false){
			tmp = Q.front();
			Q.pop();

			if(tmp.current == goal){
				printf("%d\n",t_limit - tmp.ttl+1);
				FLG = true;

				while(!Q.empty())Q.pop();

				memo[start][goal] = t_limit - tmp.ttl+1;

				break;
			}

			if(tmp.ttl > 0 && tmp.went_num < n){
				for(int i=1; i <= n; i++){
					if(i != tmp.current && tmp.checkTable[i] == 0 && table[tmp.current][i] == 1){
						if(memo[i][goal] > 0 && memo[i][goal] < tmp.ttl){
							printf("%d\n",t_limit-tmp.ttl+memo[i][goal]+1);
							memo[start][goal] = t_limit-tmp.ttl+memo[i][goal]+1;
							FLG = true;
							while(!Q.empty())Q.pop();
							break;
						}

						Packet p = tmp;
						p.ttl--;
						p.set(i);
						Q.push(p);
					}
				}
			}
		}

		if(!FLG){
			printf("NA\n");
		}

	}

    return 0;
}