#input
N, M, L = map(int, input().split())
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
    A[i], B[i], C[i] = map(int, input().split())
Q = int(input())
s = [0] * Q
t = [0] * Q
for i in range(Q):
    s[i], t[i] = map(int, input().split())

#output
from scipy.sparse.csgraph import floyd_warshall, shortest_path, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
import numpy as np

#便宜上A, Bを-1する。
for i in range(M):
    A[i] -= 1
    B[i] -= 1

#FW法で各経路の最短距離を計算する。
graph = csr_matrix((C, (A, B)), shape = (N, N))
dist_matrix = floyd_warshall(csgraph = graph, directed = False, return_predecessors = False)

graph2 = np.full((N, N), np.inf)
graph2[dist_matrix  <= L] = 1
graph2 = csr_matrix(graph2)
dist_matrix2 = floyd_warshall(csgraph = graph2, directed = False, return_predecessors = False)

for q in range(Q):
    if dist_matrix2[s[q]-1][t[q]-1] < 10000000:
        print(int(dist_matrix2[s[q]-1][t[q]-1]-1))
    else:
        print(-1) N, M, L = map(int, input().split()) N 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):
    A[i], B[i], C[i] = map(int, input().split()) i range(M) range M A[i], B[i], C[i] = map(int, input().split()) A[i] A i map(int, input().split()) map int input().split() ().split () input split B[i] B i C[i] C i Q = int(input()) Q int(input()) int input() input s = [0] * Q s [0] * Q [0] 0 Q t = [0] * Q t [0] * Q [0] 0 Q for i in range(Q):
    s[i], t[i] = map(int, input().split())

#output i range(Q) range Q s[i], t[i] = map(int, input().split()) s[i] s i map(int, input().split()) map int input().split() ().split () input split t[i] t i from scipy.sparse.csgraph import floyd_warshall, shortest_path, dijkstra, bellman_ford, johnson from scipy.sparse import csr_matrix import numpy as np numpy for i in range(M):
    A[i] -= 1
    B[i] -= 1

#FW法で各経路の最短距離を計算する。 i range(M) range M A[i] -= 1 A[i] A i 1 B[i] -= 1 B[i] B i 1 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_matrix = floyd_warshall(csgraph = graph, directed = False, return_predecessors = False) dist_matrix floyd_warshall(csgraph = graph, directed = False, return_predecessors = False) floyd_warshall csgraph = graph csgraph graph directed = False directed False return_predecessors = False return_predecessors 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_matrix  <= L] = 1 graph2[dist_matrix  <= L] graph2 dist_matrix  <= L dist_matrix L 1 graph2 = csr_matrix(graph2) graph2 csr_matrix(graph2) csr_matrix graph2 dist_matrix2 = floyd_warshall(csgraph = graph2, directed = False, return_predecessors = False) dist_matrix2 floyd_warshall(csgraph = graph2, directed = False, return_predecessors = False) floyd_warshall csgraph = graph2 csgraph graph2 directed = False directed False return_predecessors = False return_predecessors False for q in range(Q):
    if dist_matrix2[s[q]-1][t[q]-1] < 10000000:
        print(int(dist_matrix2[s[q]-1][t[q]-1]-1))
    else:
        print(-1) q range(Q) range Q if dist_matrix2[s[q]-1][t[q]-1] < 10000000:
        print(int(dist_matrix2[s[q]-1][t[q]-1]-1))
    else:
        print(-1) dist_matrix2[s[q]-1][t[q]-1] < 10000000 dist_matrix2[s[q]-1][t[q]-1] [s[q]-1] dist_matrix2 s[q]-1 s[q] s q 1 t[q]-1 t[q] t q 1 10000000 print(int(dist_matrix2[s[q]-1][t[q]-1]-1)) print int(dist_matrix2[s[q]-1][t[q]-1]-1) int dist_matrix2[s[q]-1][t[q]-1]-1 dist_matrix2[s[q]-1][t[q]-1] [s[q]-1] dist_matrix2 s[q]-1 s[q] s q 1 t[q]-1 t[q] t q 1 1 print(-1) print -1 graph = csr_matrix((C, (A, B)), shape = (N, N)) csr_matrix((C, (A, B)), shape = (N, N)) graph graph2 = csr_matrix(graph2) csr_matrix(graph2) graph2 C = [0] * M [0] * M C L = map(int, input().split()) map(int, input().split()) L s = [0] * Q [0] * Q s graph2 = np.full((N, N), np.inf) np.full((N, N), np.inf) graph2 t = [0] * Q [0] * Q t B = [0] * M [0] * M B dist_matrix2 = floyd_warshall(csgraph = graph2, directed = False, return_predecessors = False) floyd_warshall(csgraph = graph2, directed = False, return_predecessors = False) dist_matrix2 A = [0] * M [0] * M A N, M, L = map(int, input().split()) map(int, input().split()) N dist_matrix = floyd_warshall(csgraph = graph, directed = False, return_predecessors = False) floyd_warshall(csgraph = graph, directed = False, return_predecessors = False) dist_matrix Q = int(input()) int(input()) Q M, L = map(int, input().split()) map(int, input().split()) M
#input
N, M, L = map(int, input().split())
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
    A[i], B[i], C[i] = map(int, input().split())
Q = int(input())
s = [0] * Q
t = [0] * Q
for i in range(Q):
    s[i], t[i] = map(int, input().split())

#output
from scipy.sparse.csgraph import floyd_warshall, shortest_path, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
import numpy as np

#便宜上A, Bを-1する。
for i in range(M):
    A[i] -= 1
    B[i] -= 1

#FW法で各経路の最短距離を計算する。
graph = csr_matrix((C, (A, B)), shape = (N, N))
dist_matrix = floyd_warshall(csgraph = graph, directed = False, return_predecessors = False)

graph2 = np.full((N, N), np.inf)
graph2[dist_matrix  <= L] = 1
graph2 = csr_matrix(graph2)
dist_matrix2 = floyd_warshall(csgraph = graph2, directed = False, return_predecessors = False)

for q in range(Q):
    if dist_matrix2[s[q]-1][t[q]-1] < 10000000:
        print(int(dist_matrix2[s[q]-1][t[q]-1]-1))
    else:
        print(-1)