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 (e <- es) if (g(e._1) + 1 < g(e._2)) {g(e._2) = g(e._1) + 1; flag = true}
        }
        println(if (v >= g(d)) g(d) else "NA")
    }
}