import sys
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.buffer.readline
INF = 10**12

N, M, L = map(int, input().split())
G = np.zeros((N, N), dtype=np.int64)
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    G[a][b] = c
    G[b][a] = c
Q = int(input())
ST = [list(map(int, input().split())) for _ in range(Q)]

fw = floyd_warshall(G)
path = np.full((N, N), INF, dtype=np.int64)
path[fw <= L] = 1
path_fw = (floyd_warshall(path) + 0.5).astype(np.int64)

ans = []
for s, t in ST:
    s -= 1
    t -= 1
    if path_fw[s][t] >= INF:
        ans.append(-1)
        continue
    ans.append(path_fw[s][t]-1)

print(*ans, sep="\n") import sys sys import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline INF = 10**12 INF 10**12 10 12 N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L G = np.zeros((N, N), dtype=np.int64) G np.zeros((N, N), dtype=np.int64) np.zeros np zeros (N, N) N N dtype=np.int64 dtype np.int64 np int64 for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    G[a][b] = c
    G[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 G[a][b] = c G[a][b] [a] G a b c G[b][a] = c G[b][a] [b] G b a c Q = int(input()) Q int(input()) int input() input list(map(int, input().split())) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ST = [list(map(int, input().split())) for _ in range(Q)] ST [list(map(int, input().split())) for _ in range(Q)] fw = floyd_warshall(G) fw floyd_warshall(G) floyd_warshall G path = np.full((N, N), INF, dtype=np.int64) path np.full((N, N), INF, dtype=np.int64) np.full np full (N, N) N N INF dtype=np.int64 dtype np.int64 np int64 path[fw <= L] = 1 path[fw <= L] path fw <= L fw L 1 path_fw = (floyd_warshall(path) + 0.5).astype(np.int64) path_fw (floyd_warshall(path) + 0.5).astype(np.int64) floyd_warshall(path) + 0.5).astype floyd_warshall(path) + 0.5 floyd_warshall(path) floyd_warshall path 0.5 astype np.int64 np int64 ans = [] ans [] for s, t in ST:
    s -= 1
    t -= 1
    if path_fw[s][t] >= INF:
        ans.append(-1)
        continue
    ans.append(path_fw[s][t]-1) s t ST s -= 1 s 1 t -= 1 t 1 if path_fw[s][t] >= INF:
        ans.append(-1)
        continue
     path_fw[s][t] >= INF path_fw[s][t] [s] path_fw s t INF ans.append(-1) ans.append ans append -1 continue ans.append(path_fw[s][t]-1) ans.append ans append path_fw[s][t]-1 path_fw[s][t] [s] path_fw s t 1 print(*ans, sep="\n") print *ans ans sep="\n" sep "\n" G = np.zeros((N, N), dtype=np.int64) np.zeros((N, N), dtype=np.int64) G path_fw = (floyd_warshall(path) + 0.5).astype(np.int64) (floyd_warshall(path) + 0.5).astype(np.int64) path_fw b, c = map(int, input().split()) map(int, input().split()) b M, L = map(int, input().split()) map(int, input().split()) M N, M, L = map(int, input().split()) map(int, input().split()) N Q = int(input()) int(input()) Q input = sys.stdin.buffer.readline sys.stdin.buffer.readline input c = map(int, input().split()) map(int, input().split()) c a, b, c = map(int, input().split()) map(int, input().split()) a a -= 1 1 a b -= 1 1 b ST = [list(map(int, input().split())) for _ in range(Q)] [list(map(int, input().split())) for _ in range(Q)] ST ans = [] [] ans path = np.full((N, N), INF, dtype=np.int64) np.full((N, N), INF, dtype=np.int64) path INF = 10**12 10**12 INF s -= 1 1 s L = map(int, input().split()) map(int, input().split()) L fw = floyd_warshall(G) floyd_warshall(G) fw t -= 1 1 t
import sys
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.buffer.readline
INF = 10**12

N, M, L = map(int, input().split())
G = np.zeros((N, N), dtype=np.int64)
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    G[a][b] = c
    G[b][a] = c
Q = int(input())
ST = [list(map(int, input().split())) for _ in range(Q)]

fw = floyd_warshall(G)
path = np.full((N, N), INF, dtype=np.int64)
path[fw <= L] = 1
path_fw = (floyd_warshall(path) + 0.5).astype(np.int64)

ans = []
for s, t in ST:
    s -= 1
    t -= 1
    if path_fw[s][t] >= INF:
        ans.append(-1)
        continue
    ans.append(path_fw[s][t]-1)

print(*ans, sep="\n")
