#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
typedef pair<int,int> P;
const int INF =10000000;
int n;
int d[101][101];
int main()
{
  int r,k;
  while(cin>>n){
    for(int i = 0;i < 101;i++){
      for(int j = 0;j <101;j++){
	d[i][j]= INF;
	if(i==j)
	  d[i][j] = 0;
      }
    }
    for(int i = 1;i <=n;i++){
      cin>>r;
      cin>>k;
      for(int j = 0;j < k;j++){
	int x;
	cin>>x;
	d[r][x] = 1;
      }
    }
    for(int i = 1;i <=n;i++){
      for(int j = 1;j <=n;j++){
	for(int k = 1;k <=n;k++){
	  d[i][j] =min(d[i][j],d[i][k]+d[k][j]);
	}
      }
    }
    int p;
    cin>>p;
    int s1,d1,v1;
    for(int i = 0;i <p;i++){
      cin>>s1>>d1>>v1;
      if(d[s1][d1]+1<=v1){
	cout <<d[s1][d1]+1<<endl;
      }else{
	cout <<"NA"<<endl;
      }
    }
  }
  return 0;
}