fun main(args: Array<String>) {
    val (N, M, L) = readLine()!!.split(" ").map{it.toInt()}
    val INF = 1e15.toLong()
    val d = Array(N + 1) { i -> LongArray(N + 1) {
        if (i == it) 0L else INF
    } }

    for (i in 1..M) {
        val (A, B, C) = readLine()!!.split(" ").map{it.toInt()}
        d[A][B] = C.toLong()
        d[B][A] = C.toLong()
    }

    for (k in d.indices) for (i in d.indices) for (j in d.indices) {
        d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j])
    }

    for (i in d.indices) for (j in d.indices) {
        if (i == j) continue

        d[i][j] = if (d[i][j] <= L) 1 else INF
    }

    for (k in d.indices) for (i in d.indices) for (j in d.indices) {
        d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j])
    }

    val Q = readLine()!!.toInt()
    for (i in 1..Q) {
        val (s, t) = readLine()!!.split(" ").map{it.toInt()}

        if (d[s][t] == INF) {
            println(-1)
        } else {
            println(d[s][t] - 1)
        }
    }
}