import java.util.Scanner

val INF = Long.MAX_VALUE
fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val m = scn.nextInt()
	val l = scn.nextInt()
	var map = Array(n){ a -> LongArray(n){ b-> if (a==b) 0 else INF }}
	repeat(m) {
		val a = scn.nextInt() - 1
		val b = scn.nextInt() - 1
		val c = scn.nextLong()
		map[a][b] = c
		map[b][a] = c
	}
	map = wfa(map)
	for (a in 0 until n) {
		for (b in 0 until n) {
			if (a!=b) {
				if (map[a][b]>l) map[a][b] = INF
				else map[a][b] = 1
			}
		}
	}
	map = wfa(map)
	val q = scn.nextInt()
	repeat(q){
		val s = scn.nextInt() - 1
		val t = scn.nextInt() - 1
		println(if (map[s][t]!=INF) map[s][t]-1 else -1)
	}
}

fun wfa(map: Array<LongArray>): Array<LongArray>{
	for (k in map.indices){
		for (b in map.indices){
			for (e in map.indices){
				if (map[b][k]==INF || map[k][e]==INF) continue
				val keiyu = map[b][k] + map[k][e]
				if (map[b][e] > keiyu) {
					map[b][e] = keiyu
				}
			}
		}
	}
	return map
}