#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef vector<int> vi;
int main(){
  int n,m; cin>>n;

  int adj[100][100]={0};
  rep(i,n){
    int r,k,t; cin>>r>>k, r--;
    rep(j,k)cin>>t,adj[r][t-1]=1;
  }
  cin>>m;
  vi frontier,next; frontier.reserve(100),next.reserve(100);
  int cost[100];
  rep(i,m){
    int s,d,v; cin>>s>>d>>v,s--,d--;
    frontier.clear(); frontier.push_back(s);
    rep(j,n)cost[j]=9999; cost[s]=0;
    for(int step=0;step<v-1&&cost[d]==9999;step++){
      next.clear();
      rep(j,frontier.size())rep(h,n)if(adj[frontier[j]][h]&&cost[h]>step+1)
	cost[h]=step+1,next.push_back(h);
      frontier=next;
    }
    if(cost[d]!=9999)cout<<cost[d]+1<<endl;
    else cout<<"NA"<<endl;
  }
  return 0;
}