import numpy as np

from scipy.sparse.csgraph import shortest_path

from scipy.sparse import csr_matrix

inf = float("inf")

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

graph = np.zeros((N, N))

for _ in range(M):

    A, B, C = list(map(int, input().split()))

    graph[A-1][B-1] = C

    graph[B-1][A-1] = C

shortest_paths = shortest_path(csr_matrix(graph), directed=False, method="D")

graph = np.full((N, N), inf)

for i in range(N):

    for j in range(N):

        if shortest_paths[i][j] <= L:

            graph[i][j] = 1



Q = int(eval(input()))

def int_(num_str):

    return int(num_str) - 1



costs = shortest_path(csr_matrix(graph), directed=False, method="D")

for _ in range(Q):

    s, t = list(map(int_, input().split()))

    print((int(costs[s][t])-1 if costs[s][t] != inf else -1))
import numpy as np

from scipy.sparse.csgraph import shortest_path

from scipy.sparse import csr_matrix

inf = float("inf")

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

graph = np.zeros((N, N))

for _ in range(M):

    A, B, C = list(map(int, input().split()))

    graph[A-1][B-1] = C

    graph[B-1][A-1] = C

shortest_paths = shortest_path(csr_matrix(graph), directed=False, method="FW")

graph = np.full((N, N), inf)

for i in range(N):

    for j in range(N):

        if shortest_paths[i][j] <= L:

            graph[i][j] = 1



Q = int(eval(input()))

def int_(num_str):

    return int(num_str) - 1



costs = shortest_path(csr_matrix(graph), directed=False, method="FW")

for _ in range(Q):

    s, t = list(map(int_, input().split()))

    print((int(costs[s][t])-1 if costs[s][t] != inf else -1))
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix

inf = float("inf")
N, M, L = list(map(int, input().split()))
graph = np.zeros((N, N))
for _ in range(M):
    A, B, C = list(map(int, input().split()))
    graph[A - 1][B - 1] = C
    graph[B - 1][A - 1] = C
shortest_paths = shortest_path(csr_matrix(graph), directed=False, method="D")
graph = np.full((N, N), inf)
for i in range(N):
    for j in range(N):
        if shortest_paths[i][j] <= L:
            graph[i][j] = 1
Q = int(eval(input()))


def int_(num_str):
    return int(num_str) - 1


costs = shortest_path(csr_matrix(graph), directed=False, method="D")
for _ in range(Q):
    s, t = list(map(int_, input().split()))
    print((int(costs[s][t]) - 1 if costs[s][t] != inf else -1))

import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix

inf = float("inf")
N, M, L = list(map(int, input().split()))
graph = np.zeros((N, N))
for _ in range(M):
    A, B, C = list(map(int, input().split()))
    graph[A - 1][B - 1] = C
    graph[B - 1][A - 1] = C
shortest_paths = shortest_path(csr_matrix(graph), directed=False, method="FW")
graph = np.full((N, N), inf)
for i in range(N):
    for j in range(N):
        if shortest_paths[i][j] <= L:
            graph[i][j] = 1
Q = int(eval(input()))


def int_(num_str):
    return int(num_str) - 1


costs = shortest_path(csr_matrix(graph), directed=False, method="FW")
for _ in range(Q):
    s, t = list(map(int_, input().split()))
    print((int(costs[s][t]) - 1 if costs[s][t] != inf else -1))

-shortest_paths = shortest_path(csr_matrix(graph), directed=False, method="D") +shortest_paths = shortest_path(csr_matrix(graph), directed=False, method="FW") -costs = shortest_path(csr_matrix(graph), directed=False, method="D") +costs = shortest_path(csr_matrix(graph), directed=False, method="FW")