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 = np.zeros(M)
B = np.zeros(M)
C = np.zeros(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)
for i in range(N):
	for j in range(N):
		if dist[i, j] <= L:
			graph2[i, j] = 1
graph2 = csr_matrix(graph2)
num = shortest_path(graph2, directed=False)


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 = np.zeros(M) A np.zeros(M) np.zeros np zeros M B = np.zeros(M) B np.zeros(M) np.zeros np zeros M C = np.zeros(M) C np.zeros(M) np.zeros np zeros 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 for i in range(N):
	for j in range(N):
		if dist[i, j] <= L:
			graph2[i, j] = 1 i range(N) range N for j in range(N):
		if dist[i, j] <= L:
			graph2[i, j] = 1 j range(N) range N if dist[i, j] <= L:
			graph2[i, j] = 1 dist[i, j] <= L dist[i, j] dist i L graph2[i, j] = 1 graph2[i, j] graph2 i 1 graph2 = csr_matrix(graph2) graph2 csr_matrix(graph2) csr_matrix graph2 num = shortest_path(graph2, directed=False) num shortest_path(graph2, directed=False) shortest_path graph2 directed=False directed False 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 M, L = list(map(int, input().split())) list(map(int, input().split())) M graph2 = np.full((N, N), np.inf) np.full((N, N), np.inf) graph2 L = list(map(int, input().split())) list(map(int, input().split())) L B = np.zeros(M) np.zeros(M) B graph2 = csr_matrix(graph2) csr_matrix(graph2) graph2 num = shortest_path(graph2, directed=False) shortest_path(graph2, directed=False) num s, t = list(map(int, input().split())) list(map(int, input().split())) s N, M, L = list(map(int, input().split())) list(map(int, input().split())) N C = np.zeros(M) np.zeros(M) C Ai, Bi, Ci = list(map(int, input().split())) list(map(int, input().split())) Ai Q = int(input()) int(input()) Q Ci = list(map(int, input().split())) list(map(int, input().split())) Ci t = list(map(int, input().split())) list(map(int, input().split())) t def input():
	return sys.stdin.readline().strip() def input():
	return sys.stdin.readline().strip() input A = np.zeros(M) np.zeros(M) A dist = floyd_warshall(graph, directed=False) floyd_warshall(graph, directed=False) dist Bi, Ci = list(map(int, input().split())) list(map(int, input().split())) Bi graph = csr_matrix((C, (A, B)), shape=(N, N)) csr_matrix((C, (A, B)), shape=(N, N)) graph
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 = np.zeros(M)
B = np.zeros(M)
C = np.zeros(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)
for i in range(N):
	for j in range(N):
		if dist[i, j] <= L:
			graph2[i, j] = 1
graph2 = csr_matrix(graph2)
num = shortest_path(graph2, directed=False)


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)