import numpy as np
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
Map = np.full((N, N), 10**12, dtype='int64')
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    Map[a][b] = c
    Map[b][a] = c
Q = int(input())
Query = [tuple(map(int, input().split())) for _ in range(Q)]
graph = floyd_warshall(Map).astype('int64')
graph[graph <= L] = 1
graph[graph > L] = 10**12
A = floyd_warshall(graph).astype('int64')
for s, t in Query:
    if A[s - 1][t - 1] >= 10**12:
        print(-1)
    else:
        print(int(A[s - 1][t - 1] - 1)) import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L Map = np.full((N, N), 10**12, dtype='int64') Map np.full((N, N), 10**12, dtype='int64') np.full np full (N, N) N N 10**12 10 12 dtype='int64' dtype 'int64' for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    Map[a][b] = c
    Map[b][a] = 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 a -= 1 a 1 b -= 1 b 1 Map[a][b] = c Map[a][b] [a] Map a b c Map[b][a] = c Map[b][a] [b] Map b a c Q = int(input()) Q int(input()) int input() input tuple(map(int, input().split())) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split Query = [tuple(map(int, input().split())) for _ in range(Q)] Query [tuple(map(int, input().split())) for _ in range(Q)] graph = floyd_warshall(Map).astype('int64') graph floyd_warshall(Map).astype('int64') (Map).astype (Map) floyd_warshall Map astype 'int64' graph[graph <= L] = 1 graph[graph <= L] graph graph <= L graph L 1 graph[graph > L] = 10**12 graph[graph > L] graph graph > L graph L 10**12 10 12 A = floyd_warshall(graph).astype('int64') A floyd_warshall(graph).astype('int64') (graph).astype (graph) floyd_warshall graph astype 'int64' for s, t in Query:
    if A[s - 1][t - 1] >= 10**12:
        print(-1)
    else:
        print(int(A[s - 1][t - 1] - 1)) s t Query if A[s - 1][t - 1] >= 10**12:
        print(-1)
    else:
        print(int(A[s - 1][t - 1] - 1)) A[s - 1][t - 1] >= 10**12 A[s - 1][t - 1] [s - 1] A s - 1 s 1 t - 1 t 1 10**12 10 12 print(-1) print -1 print(int(A[s - 1][t - 1] - 1)) print int(A[s - 1][t - 1] - 1) int A[s - 1][t - 1] - 1 A[s - 1][t - 1] [s - 1] A s - 1 s 1 t - 1 t 1 1 b, c = map(int, input().split()) map(int, input().split()) b a, b, c = map(int, input().split()) map(int, input().split()) a A = floyd_warshall(graph).astype('int64') floyd_warshall(graph).astype('int64') A N, M, L = map(int, input().split()) map(int, input().split()) N Map = np.full((N, N), 10**12, dtype='int64') np.full((N, N), 10**12, dtype='int64') Map a -= 1 1 a Query = [tuple(map(int, input().split())) for _ in range(Q)] [tuple(map(int, input().split())) for _ in range(Q)] Query graph = floyd_warshall(Map).astype('int64') floyd_warshall(Map).astype('int64') graph b -= 1 1 b L = map(int, input().split()) map(int, input().split()) L Q = int(input()) int(input()) Q M, L = map(int, input().split()) map(int, input().split()) M c = map(int, input().split()) map(int, input().split()) c
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
Map = np.full((N, N), 10**12, dtype='int64')
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    Map[a][b] = c
    Map[b][a] = c
Q = int(input())
Query = [tuple(map(int, input().split())) for _ in range(Q)]
graph = floyd_warshall(Map).astype('int64')
graph[graph <= L] = 1
graph[graph > L] = 10**12
A = floyd_warshall(graph).astype('int64')
for s, t in Query:
    if A[s - 1][t - 1] >= 10**12:
        print(-1)
    else:
        print(int(A[s - 1][t - 1] - 1))
