#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int , int> pii;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
const int INF = 1<<30;

int n ;
vector<int> way[120];

int mini(int s,int d,int v);

int main(void){
  cin>>n;
  rep(i,n){
    int r,k;
    cin>>r>>k;
    while(k--){
      int t;
      cin>>t;
      way[r].push_back(t);
    }
  }
  int p;
  cin>>p;
  
  while(p--){
    int s,d,v;
    cin>>s>>d>>v;
    int cost = mini(s,d,v);
    if(cost == INF) cout<< "NA" << endl;
    else cout<< cost << endl;
  }
  return 0;
  
  
}
int mini(int s, int d, int v)
{
    int diff[128];
    queue<pii> q;
     
    fill(diff, diff + n + 1, INF);
    q.push(pii(s, 1));
    diff[s] = 1;
    while (!q.empty()){
        pii p = q.front(); q.pop();
         
        if (diff[p.first] < p.second) continue;
        for (int i = 0; i < way[p.first].size(); i++){
            int tmp = way[p.first][i];
             
            if (diff[tmp] > diff[p.first] + 1){
                diff[tmp] = diff[p.first] + 1;
                q.push(pii(tmp, diff[tmp]));
            }
        }
    }
     
    if (diff[d] == INF || diff[d] > v) return INF;
    else return diff[d];
}