#include <stdio.h>
#include <memory.h>

int G[100][100] = {0}; // [from][to] = 0, 1
int k[100];            // edgenum
int n;
int qhead = 0, qtail = 0;
int queue[100];
int cost[100], dat[100];

void bfs(int);
void PushQueue(int);
int PopQueue();
int isQueueEmpty();

int main (void) {
  int i, j;
  int from_edge, to_edge;

  scanf("%d", &n);
  
  for(i = 0; i < n; i++) {
    scanf("%d", &from_edge);
    scanf("%d", &k[from_edge-1]);
    for(j = 0; j < k[from_edge-1]; j++) {
      scanf("%d", &to_edge);
      G[from_edge-1][to_edge-1] = 1;
    }
  }

  //for (i = 0; i < n; i++) {
  //  for (j = 0; j < n; j++) {
  //    printf("%d ", G[i][j]);
  //  }
  //  printf("\n");
  //}

  int n_packet;
  int from_node, to_node, ttl;

  scanf("%d", &n_packet);
  
  for (i = 0; i < n_packet; i++) {
    scanf("%d", &from_node);
    scanf("%d", &to_node);
    scanf("%d", &ttl);

    cost[from_node-1] = 0;
    qhead = 0; qtail = 0;
    bfs(from_node);

    //for (j = 0; j < n; j++) { printf("cost[%d] = %d\n", j, cost[j]); }

    if (cost[to_node-1] < ttl) {
      printf("%d\n", cost[to_node-1] + 1);  // senderの通過も含める
    } else {
      printf("NA\n");
    }
  }

  return 0;
}

void bfs(int st_node) {
  int i;
  int u, v = st_node - 1;
  int visited[n];

  for (i = 0; i < n; i++) {
    visited[i] = 0;
  }
  
  PushQueue(v);
  visited[v] = 1;

  while(!isQueueEmpty()) {
    u = PopQueue();
    //printf("u:%d\n", u);
    for(v = 0; v < n; v++) {
      if(G[u][v] && !visited[v]) {
	PushQueue(v);
	cost[v] = cost[u] + 1;
	visited[v] = 1;
      }
    }

  }
}

void PushQueue(int num) {
  queue[qtail] = num;
  qtail++;
}
int PopQueue() {
  int ret;

  ret = queue[qhead];
  qhead++;
  return ret;
}

int isQueueEmpty() {
  if (qtail == qhead) return 1; // Queue is empty.

  return 0; // Queue exists.
}