#include<iostream>

int main(void)
{
  int n,p,r,k,t[101],a,count[101],flag;
  int queue[10000],head=0,tail=0;
  int router[101][101],visited[101],i,j,b,fg;
  
  struct mail{
    int s;
    int d;
    int v[101];
  }packet[101];
  
  for(i=0;i<101;i++)
    {
      for(j=0;j<101;j++)
	{
	  router[i][j]=0;
	}
    }
  
  scanf("%d",&n);
  
  for(i=1;i<=n;i++)
    {
      scanf("%d%d",&r,&k);
      
      for(j=1;j<=k;j++)
	{
	  scanf("%d",&t[j]);
	  router[r][t[j]]=1;
	}
    }
  
  for(i=1;i<=n;i++)
    {
      router[i][i]=0;
    }
  
  scanf("%d",&p);
  
  for(i=1;i<=p;i++)
    {
      scanf("%d%d%d",&packet[i].s,&packet[i].d,&packet[i].v[1]);
    }
  
  for(i=1;i<=p;i++)
    {
      for(j=1;j<=p;j++)
	{
	  packet[i].v[j]=packet[i].v[1];
	}
    }
  
  for(i=1;i<=p;i++)
    {
      //printf("A\n");
      count[packet[i].s]=1;
      queue[tail++]=packet[i].s;
      
      for(b=0;b<=n;b++)
	visited[b]=0;
      
      visited[packet[i].s]=1;
      fg=0;
      //printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n");
      while(head!=tail)
	{
	  
	  a=queue[head++];
	  
	  for(j=1;j<=n;j++)
	    {
	      //printf("%dB\n",packet[i].v[j]);
	      //printf("%d\n",packet[i].v[j]);
	      
	      if(router[a][j]==1 && visited[j]==0)
		{
		  queue[tail++]=j;
		  visited[j]=1;
		  count[j]=count[a]+1;
		  packet[i].v[j]=packet[i].v[a]-1;
		  //printf("%d==%d\n",j,packet[i].d);
		  if(j==packet[i].d && packet[i].v[j]>0)printf("%d\n",count[packet[i].d]);
		  else if(fg==0 && packet[i].v[j]==-1 && a!=packet[i].d)
		    {
		      printf("NA\n");
		      fg=1;
		    }
		  
		} 
	      
	    }
	  //printf("\n");
	}
      
    }
  return 0;
}