object Main extends App {
    val in = io.Source.stdin.getLines
    val n = in.next.toInt
    val es = in.take(n).flatMap(e => {
        val Array(r, _, t@_*) = e.split(" ").map(_.toInt)
        t.map((r, _))
    }).toList
    in.next
    for (Array(s, d, v) <- in.map(_.split(" ").map(_.toInt))) {
        val g = Array.fill(n+1)(Int.MaxValue-100)
        g(s) = 1
        var flag = true
        while(flag) {
            flag = false
            for ((r, t) <- es)
                if (g(r) + 1 < g(t)) {
                    g(t) = g(r) + 1
                    flag = true
                }
        }
        println(if (v >= g(d)) g(d) else "NA")
    }
}