#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

#define MAX 100000

int main(){
  int n;
  int dist[100][100];
  scanf("%d",&n);
  REP(i,n){
    int k, m;
    scanf("%d%d",&k,&m);
    REP(j,n) dist[k-1][j] = MAX;
    dist[k-1][k-1] = 0;
    REP(j,m){
      int d;
      scanf("%d",&d);
      dist[k-1][d-1] = 1;
    }
  }

  REP(k,n) REP(i,n) REP(j,n)
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

  int m;
  scanf("%d",&m);
  REP(i,m){
    int a, b, c;
    scanf("%d%d%d",&a,&b,&c);
    if(dist[a-1][b-1] == MAX || dist[a-1][b-1] + 1 > c)
      puts("NA");
    else
      printf("%d\n",dist[a-1][b-1]+1);
  }
  return 0;
}