object Main extends App {
    val inf = Int.MaxValue-10000
    val in = io.Source.stdin.getLines
    val n = in.next.toInt
    val e = in.take(n).flatMap(x => {val y = x.split(" ").map(_.toInt); y.drop(2).map(z => Array(y(0), z))}).toList
    for (Array(s, d, v) <- in.take(in.next.toInt).map(_.split(" ").map(_.toInt))) {
        val g = Array.fill(n+1)(inf)
        g(s) = 1
        var flag = true
        while(flag) {
            flag = false
            for (b <- e) if (g(b(0)) + 1 < g(b(1))) {g(b(1)) = g(b(0)) + 1; flag = true}
        }
        println(if (v >= g(d)) g(d) else "NA")
    }
}