fun main(args: Array<String>) {
    val INF = 1000000001
    val (N, M, L) = readInputLine().split(" ").map { it.toInt() }
    val d = Array(N) { IntArray(N) { INF } }

    for (i in 0 until N) {
        d[i][i] = 0
    }

    for (i in 1..M) {
        val (A, B, C) = readInputLine().split(" ").map { it.toInt() }
        if (C <= L) {
            d[A - 1][B - 1] = C
            d[B - 1][A - 1] = 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])
            }
        }
    }
    
    val d2 = Array(N) { IntArray(N) { INF } }
    
    for (i in 0 until N) {
        for (j in 0 until N) {
            if (d[i][j] <= L) {
                d2[i][j] = 1
            }
        }
    }
    
    for (i in 0 until N) {
        d2[i][i] = 0
    }

    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 = readInputLine().toInt()
    
    for (i in 1..Q) {
        val (s, t) = readInputLine().split(" ").map { it.toInt() - 1 }
        
        if (d2[s][t] == INF) {
            println(-1)
        } else {
            println(d2[s][t] - 1)
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}
