#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main() {
 int d[100][100],rn,pn,i,j,to,fr,s1,d1,v1,a,b,c,n;
 for (i=0;i<100;i++) for (j=0;j<100;j++) d[i][j]=999;
 cin >> n;
 for (i=0;i<n;i++) {
   cin >> to >> rn; 
   for (j=0;j<rn;j++) { cin >> fr; d[to-1][fr-1]=1;}
 }
 for (a=0;a<100;a++) for (b=0;b<100;b++) for (c=0;c<100;c++) d[b][c]=min(d[b][c],d[b][a]+d[a][c]);
 cin >> pn;
 for (i=0;i<pn;i++) {
   cin >> s1 >> d1 >> v1;
   if (d[s1-1][d1-1]>v1-1) cout << "NA"; else cout << d[s1-1][d1-1]+1;
   cout << endl;
 }
return 0;
 }