#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int INF = (1<<21);

class state{
public:
  int d,n;
  state(int d=0,int n=0):d(d),n(n){}
};

int main(){
  int n;
  while(cin >> n){
    bool d[100][100];
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) d[i][j] = false;
    for(int i=0;i<n;i++){
      int a,b;
      cin >> a >> b;
      a--;
      for(int j=0;j<b;j++){
	int c;
	cin >> c;
	c--;
	d[a][c] = true;
      }
    }

    int m;
    cin >> m;
    while(m--){
      int a,b,c;
      queue<state> Q;
      bool f[100];
      for(int i=0;i<n;i++) f[i] = false;
      cin >> a >> b >> c;
      a--;
      b--;

      state u(a,1);
      int ans = INF;
      Q.push(u);

      while(!Q.empty()){
	u = Q.front();
	Q.pop();
	f[u.d] = true;

	if(u.d == b){
	  if(u.n <= c) ans = u.n;
	  break;
	}

	for(int i=0;i<n;i++){
	  if(!f[i] && d[u.d][i]){
	    state v = u;
	    v.d = i;
	    v.n++;
	    Q.push(v);
	  }
	}
      }

      if(ans == INF) cout << "NA" << endl;
      else cout << ans << endl;

    }
  }
  return 0;
}