// resubmission for after contest tedtcase
fun main(args: Array<String>) {
    abc143e()
}

private data class Distance(val from: Int, val to: Int, val cost: Int)
private data class Query(val from: Int, val to: Int)

fun abc143e() {
    val (n, m, l) = readLine()!!.split(" ").map { it.toInt() }
    val lines = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }
        .map { Distance(it[0] - 1, it[1] - 1, it[2]) }
    val q = readLine()!!.toInt()
    val queries = (1..q).map { readLine()!!.split(" ").map { it.toInt() - 1 } }
        .map { Query(it[0], it[1]) }

    // 町iから町jへの移動距離
    val distances = Array(n) { IntArray(n) { Int.MAX_VALUE / 2 } }

    lines.forEach { line ->
        distances[line.from][line.to] = line.cost
        distances[line.to][line.from] = line.cost
    }

    for (k in 0 until n) {
        for (i in 0 until n) {
            for (j in 0 until n) {
                distances[i][j] = Math.min(distances[i][j], distances[i][k] + distances[k][j])
            }
        }
    }

    // 町iから町jへ移動するための最低燃料補給回数
    val fuelRefills = Array(n) { IntArray(n) { Int.MAX_VALUE / 2 } }

    distances.forEachIndexed { from, tos ->
        tos.forEachIndexed { to, cost ->
            if (cost <= l) fuelRefills[from][to] = 1
        }
    }

    for (k in 0 until n) {
        for (i in 0 until n) {
            for (j in 0 until n) {
                fuelRefills[i][j] = Math.min(fuelRefills[i][j], fuelRefills[i][k] + fuelRefills[k][j])
            }
        }
    }

    val answer = queries.map { query ->
        fuelRefills[query.from][query.to].let { if (it == Int.MAX_VALUE / 2) -1 else it - 1 }
    }.joinToString(System.lineSeparator())

    println(answer)
}
