fun main(args: Array<String>){
    val (N, M, L) = listOfInt()
    val INF = 1001001001
    var D = Array<Array<Int>>(N) { Array<Int>(N) { INF } }
    repeat(N) { D[it][it] = 0 }
    repeat(M) {
        var (a, b, c) = listOfInt()
        a -= 1; b -= 1
        D[a][b] = c; D[b][a] = c
    }
    for (k in 0 until N) {
        for (i in 0 until N) {
            for (j in 0 until N) {
                D[i][j] = Math.min(D[i][j], D[i][k] + D[k][j])
            }
        }
    }

    var D2 = Array<Array<Int>>(N) { Array<Int>(N) { INF } }
    repeat(N) { D2[it][it] = 0 }
    for (i in 0 until N) {
        for (j in 0 until N) {
            if (D[i][j] <= L) D2[i][j] = 1
        }
    }
    for (k in 0 until N) {
        for (i in 0 until N) {
            for (j in 0 until N) {
                D2[i][j] = Math.min(D2[i][j], D2[i][k] + D2[k][j])
            }
        }
    }
    val Q = nextInt()
    repeat(Q) {
        val (s, t) = listOfInt(-1)
        val ans = if (D2[s][t] == INF) -1 else D2[s][t] - 1
        println(ans)
    }
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { it.toInt() + delta }