from scipy.sparse import csr_matrix #pypyだとエラーになるので、pythonを使うこと
from scipy.sparse.csgraph import shortest_path, floyd_warshall
import numpy as np

import sys
def input():
	return sys.stdin.readline().strip()

N, M, L = list(map(int, input().split()))

A = [0]*M
B = [0]*M
C = [0]*M
for i in range(M):
	Ai, Bi, Ci = list(map(int, input().split()))
	A[i] = Ai - 1
	B[i] = Bi - 1
	C[i] = Ci

graph = csr_matrix((C, (A, B)), shape=(N, N))
#print(graph)
dist = floyd_warshall(graph, directed=False)

graph2 = np.full((N, N), np.inf)
graph2[dist <= L] = 1
graph2 = csr_matrix(graph2)
num = floyd_warshall(graph2, directed=False)


num = num.tolist()

Q = int(input())
for q in range(Q):
	s, t = list(map(int, input().split()))
	if num[s - 1][t - 1] < 10000000:
		print(int(num[s - 1][t - 1] - 1))
	else:
		print(-1) from scipy.sparse import csr_matrix from scipy.sparse.csgraph import shortest_path, floyd_warshall import numpy as np numpy import sys sys def input():
	return sys.stdin.readline().strip() input return sys.stdin.readline().strip() sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip N, M, L = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M L A = [0]*M A [0]*M [0] 0 M B = [0]*M B [0]*M [0] 0 M C = [0]*M C [0]*M [0] 0 M for i in range(M):
	Ai, Bi, Ci = list(map(int, input().split()))
	A[i] = Ai - 1
	B[i] = Bi - 1
	C[i] = Ci i range(M) range M Ai, Bi, Ci = list(map(int, input().split())) Ai list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split Bi Ci A[i] = Ai - 1 A[i] A i Ai - 1 Ai 1 B[i] = Bi - 1 B[i] B i Bi - 1 Bi 1 C[i] = Ci C[i] C i Ci graph = csr_matrix((C, (A, B)), shape=(N, N)) graph csr_matrix((C, (A, B)), shape=(N, N)) csr_matrix (C, (A, B)) C (A, B) A B shape=(N, N) shape (N, N) N N dist = floyd_warshall(graph, directed=False) dist floyd_warshall(graph, directed=False) floyd_warshall graph directed=False directed False graph2 = np.full((N, N), np.inf) graph2 np.full((N, N), np.inf) np.full np full (N, N) N N np.inf np inf graph2[dist <= L] = 1 graph2[dist <= L] graph2 dist <= L dist L 1 graph2 = csr_matrix(graph2) graph2 csr_matrix(graph2) csr_matrix graph2 num = floyd_warshall(graph2, directed=False) num floyd_warshall(graph2, directed=False) floyd_warshall graph2 directed=False directed False num = num.tolist() num num.tolist() num.tolist num tolist Q = int(input()) Q int(input()) int input() input for q in range(Q):
	s, t = list(map(int, input().split()))
	if num[s - 1][t - 1] < 10000000:
		print(int(num[s - 1][t - 1] - 1))
	else:
		print(-1) q range(Q) range Q s, t = list(map(int, input().split())) s list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split t if num[s - 1][t - 1] < 10000000:
		print(int(num[s - 1][t - 1] - 1))
	else:
		print(-1) num[s - 1][t - 1] < 10000000 num[s - 1][t - 1] [s - 1] num s - 1 s 1 t - 1 t 1 10000000 print(int(num[s - 1][t - 1] - 1)) print int(num[s - 1][t - 1] - 1) int num[s - 1][t - 1] - 1 num[s - 1][t - 1] [s - 1] num s - 1 s 1 t - 1 t 1 1 print(-1) print -1 s, t = list(map(int, input().split())) list(map(int, input().split())) s t = list(map(int, input().split())) list(map(int, input().split())) t B = [0]*M [0]*M B graph2 = np.full((N, N), np.inf) np.full((N, N), np.inf) graph2 def input():
	return sys.stdin.readline().strip() def input():
	return sys.stdin.readline().strip() input N, M, L = list(map(int, input().split())) list(map(int, input().split())) N A = [0]*M [0]*M A C = [0]*M [0]*M C dist = floyd_warshall(graph, directed=False) floyd_warshall(graph, directed=False) dist Ci = list(map(int, input().split())) list(map(int, input().split())) Ci graph = csr_matrix((C, (A, B)), shape=(N, N)) csr_matrix((C, (A, B)), shape=(N, N)) graph num = floyd_warshall(graph2, directed=False) floyd_warshall(graph2, directed=False) num num = num.tolist() num.tolist() num graph2 = csr_matrix(graph2) csr_matrix(graph2) graph2 M, L = list(map(int, input().split())) list(map(int, input().split())) M L = list(map(int, input().split())) list(map(int, input().split())) L Bi, Ci = list(map(int, input().split())) list(map(int, input().split())) Bi Q = int(input()) int(input()) Q Ai, Bi, Ci = list(map(int, input().split())) list(map(int, input().split())) Ai
from scipy.sparse import csr_matrix #pypyだとエラーになるので、pythonを使うこと
from scipy.sparse.csgraph import shortest_path, floyd_warshall
import numpy as np

import sys
def input():
	return sys.stdin.readline().strip()

N, M, L = list(map(int, input().split()))

A = [0]*M
B = [0]*M
C = [0]*M
for i in range(M):
	Ai, Bi, Ci = list(map(int, input().split()))
	A[i] = Ai - 1
	B[i] = Bi - 1
	C[i] = Ci

graph = csr_matrix((C, (A, B)), shape=(N, N))
#print(graph)
dist = floyd_warshall(graph, directed=False)

graph2 = np.full((N, N), np.inf)
graph2[dist <= L] = 1
graph2 = csr_matrix(graph2)
num = floyd_warshall(graph2, directed=False)


num = num.tolist()

Q = int(input())
for q in range(Q):
	s, t = list(map(int, input().split()))
	if num[s - 1][t - 1] < 10000000:
		print(int(num[s - 1][t - 1] - 1))
	else:
		print(-1)