import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
inf = float("inf")
N, M, L = map(int, input().split())
graph = np.zeros((N, N))
for _ in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C
shortest_paths = dijkstra(csr_matrix(graph), directed=False)
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(input())
def int_(num_str):
    return int(num_str) - 1

costs = dijkstra(csr_matrix(graph), directed=False)
for _ in range(Q):
    s, t = map(int_, input().split())
    print(int(costs[s][t])-1 if costs[s][t] != inf else -1) import numpy as np numpy from scipy.sparse.csgraph import dijkstra from scipy.sparse import csr_matrix inf = float("inf") inf float("inf") float "inf" N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L graph = np.zeros((N, N)) graph np.zeros((N, N)) np.zeros np zeros (N, N) N N for _ in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C _ range(M) range M A, B, C = map(int, input().split()) A map(int, input().split()) map int input().split() ().split () input split B C graph[A-1][B-1] = C graph[A-1][B-1] [A-1] graph A-1 A 1 B-1 B 1 C graph[B-1][A-1] = C graph[B-1][A-1] [B-1] graph B-1 B 1 A-1 A 1 C shortest_paths = dijkstra(csr_matrix(graph), directed=False) shortest_paths dijkstra(csr_matrix(graph), directed=False) dijkstra csr_matrix(graph) csr_matrix graph directed=False directed False graph = np.full((N, N), inf) graph np.full((N, N), inf) np.full np full (N, N) N N inf for i in range(N):
    for j in range(N):
        if shortest_paths[i][j] <= L:
            graph[i][j] = 1 i range(N) range N for j in range(N):
        if shortest_paths[i][j] <= L:
            graph[i][j] = 1 j range(N) range N if shortest_paths[i][j] <= L:
            graph[i][j] = 1 shortest_paths[i][j] <= L shortest_paths[i][j] [i] shortest_paths i j L graph[i][j] = 1 graph[i][j] [i] graph i j 1 Q = int(input()) Q int(input()) int input() input def int_(num_str):
    return int(num_str) - 1 int_ return int(num_str) - 1 int(num_str) - 1 int(num_str) int num_str 1 num_str num_str costs = dijkstra(csr_matrix(graph), directed=False) costs dijkstra(csr_matrix(graph), directed=False) dijkstra csr_matrix(graph) csr_matrix graph directed=False directed False for _ in range(Q):
    s, t = map(int_, input().split())
    print(int(costs[s][t])-1 if costs[s][t] != inf else -1) _ range(Q) range Q s, t = map(int_, input().split()) s map(int_, input().split()) map int_ input().split() ().split () input split t print(int(costs[s][t])-1 if costs[s][t] != inf else -1) print int(costs[s][t])-1 if costs[s][t] != inf else -1 costs[s][t] != inf costs[s][t] [s] costs s t inf int(costs[s][t])-1 int(costs[s][t]) int costs[s][t] [s] costs s t 1 -1 M, L = map(int, input().split()) map(int, input().split()) M C = map(int, input().split()) map(int, input().split()) C graph = np.zeros((N, N)) np.zeros((N, N)) graph L = map(int, input().split()) map(int, input().split()) L Q = int(input()) int(input()) Q def int_(num_str):
    return int(num_str) - 1 def int_(num_str):
    return int(num_str) - 1 int_ s, t = map(int_, input().split()) map(int_, input().split()) s B, C = map(int, input().split()) map(int, input().split()) B A, B, C = map(int, input().split()) map(int, input().split()) A N, M, L = map(int, input().split()) map(int, input().split()) N costs = dijkstra(csr_matrix(graph), directed=False) dijkstra(csr_matrix(graph), directed=False) costs inf = float("inf") float("inf") inf shortest_paths = dijkstra(csr_matrix(graph), directed=False) dijkstra(csr_matrix(graph), directed=False) shortest_paths graph = np.full((N, N), inf) np.full((N, N), inf) graph t = map(int_, input().split()) map(int_, input().split()) t
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
inf = float("inf")
N, M, L = map(int, input().split())
graph = np.zeros((N, N))
for _ in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C
shortest_paths = dijkstra(csr_matrix(graph), directed=False)
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(input())
def int_(num_str):
    return int(num_str) - 1

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