import java.util.*

fun <T : Comparable<T>> min(i: T, j:T):T {
    return if (i < j) i else j
}

// ABC143 E
fun main(args: Array<String>) {
    val inf = Long.MAX_VALUE
    val (N, M, L) = readLine()!!.split(" ").map { it.toInt() }
    val dp = Array(N) {Array(N) {inf} }
    val dp2 = Array(N) {Array(N) {inf} }
    val A = IntArray(M)
    val B = IntArray(M)
    val C = IntArray(M)
    for (i in 0 until M) {
        val arr = readLine()!!.split(" ").map { it.toInt() }
        dp[arr[0]-1][arr[1]-1] = arr[2].toLong()
        dp[arr[1]-1][arr[0]-1] = arr[2].toLong()
        A[i] = arr[0]
        B[i] = arr[1]
        C[i] = arr[2]
    }
    val Q = readLine()!!.toInt()
    val s = IntArray(Q)
    val t = IntArray(Q)
    for (i in 0 until Q) {
        val arr = readLine()!!.split(" ").map { it.toInt() }
        s[i] = arr[0]
        t[i] = arr[1]
    }

    warshallFloyd(dp)

    for (j in 0 until N) {
        for (i in 0 until N) {
            if (dp[i][j] <= L) {
                dp2[i][j] = 1
            }
        }
    }

    warshallFloyd(dp2)

    for(i in 0 until Q) {
        val ans = dp2[s[i]-1][t[i]-1]
        if (ans == inf) {
            println(-1)
        } else {
            println(ans -1)
        }
    }
}

fun warshallFloyd(d: Array<Array<Long>>) {
    val n = d.size
    for (k in 0 until n) {
        for (i in 0 until n) {
            for (j in 0 until n) {
                if (d[i][k] != Long.MAX_VALUE && d[k][j] != Long.MAX_VALUE) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j])
                }
            }
        }
    }
}