using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Test1 {





    class ClassMain {


       static int[,] rooterTrans = new int[101, 101];

        static void rue(int[,] roots){
            int n = roots.GetLength(0);
            bool changes ;
            do {
                changes = false;
                for (int a = 1; a < n; a++) {
                    for (int b = 0; b < n; b++) {
                        if (a == b) { continue; }
                        if (roots[a, b] != 0) {
                            //a->b
                            for (int c = 1; c < n; c++) {
                                if (c == a || c == b) { continue; }
                                if (roots[b, c] != 0) {
                                    //a->b, b->c.
                                    int newCost = roots[a, b] + roots[b, c]-1;
                                    if (roots[a, c] == 0||newCost<roots[a,c]) {
                                        roots[a, c] = newCost;
                                        //Console.WriteLine(a + "," + b + "," + c + "." + roots[a, c]);
                                        //Console.WriteLine("ab," + roots[a,b] + " bc,"+roots[b,c]);
                                        //roots[c, a] = newCost;
                                        changes = true;
                                    }//if [a,c]==0
                                }//if[b,c]!=0
                            }//Loop c
                        }//if [a,b] != 0
                    }//Loop b
                }//Loop a
                //Console.WriteLine(changes);
            } while (changes);
        }




        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                rooterTrans = new int[n+1, n+1];
                for (int i = 0; i < n; i++) {
                    int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    rooterTrans[ints[0], ints[0]] = 1;
                    for (int j = 0; j < ints[1]; j++) {
                        rooterTrans[ints[0], ints[2 + j]] = 2;
                        //rooterTrans[ints[2+j], ints[0]] = 2;
                    }
                }
                for (int i = 0; i < n+1; i++) {
                    for (int j = 0; j < n+1; j++) {
                       // Console.Write(rooterTrans[i, j]+",");
                    } 
                    //Console.WriteLine();
                }
                rue(rooterTrans);
                //Rooters init.
                int pn = int.Parse(Console.ReadLine());
                for (int i = 0; i < pn; i++) {
                    int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    int cost=rooterTrans[ints[0],ints[1]];
                    if (cost == 0 || cost > ints[2]) {
                        Console.WriteLine("NA");
                    }
                    else {
                        Console.WriteLine(cost);
                    }
                }
                break;
            }
        }
    
    }



    
}

Measured memory_bytes: 6192