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

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

G = np.full((N, N), np.inf)
np.fill_diagonal(G, 0)
for _ in range(M):
    a, b, c = map(int, input().split())
    G[a-1][b-1] = G[b-1][a-1] = c
D = floyd_warshall(G, directed=False)

G2 = np.full((N, N), np.inf)
np.fill_diagonal(G2, 0)
G2[D <= L] = 1
D2 = floyd_warshall(G2, directed=False)

Q = int(input())
for _ in range(Q):
    a, b = map(lambda x: int(x) - 1, input().split())
    if D2[a][b] == np.inf:
        print(-1)
    else:
        print(int(D2[a][b]) - 1) import numpy as np numpy from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson from scipy.sparse import csr_matrix N,M,L = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L G = np.full((N, N), np.inf) G np.full((N, N), np.inf) np.full np full (N, N) N N np.inf np inf np.fill_diagonal(G, 0) np.fill_diagonal np fill_diagonal G 0 for _ in range(M):
    a, b, c = map(int, input().split())
    G[a-1][b-1] = G[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 G[a-1][b-1] = G[b-1][a-1] = c G[a-1][b-1] [a-1] G a-1 a 1 b-1 b 1 c = G[b-1][a-1] = c G[b-1][a-1] [b-1] G b-1 b 1 a-1 a 1 c D = floyd_warshall(G, directed=False) D floyd_warshall(G, directed=False) floyd_warshall G directed=False directed False G2 = np.full((N, N), np.inf) G2 np.full((N, N), np.inf) np.full np full (N, N) N N np.inf np inf np.fill_diagonal(G2, 0) np.fill_diagonal np fill_diagonal G2 0 G2[D <= L] = 1 G2[D <= L] G2 D <= L D L 1 D2 = floyd_warshall(G2, directed=False) D2 floyd_warshall(G2, directed=False) floyd_warshall G2 directed=False directed False Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    a, b = map(lambda x: int(x) - 1, input().split())
    if D2[a][b] == np.inf:
        print(-1)
    else:
        print(int(D2[a][b]) - 1) _ range(Q) range Q a, b = map(lambda x: int(x) - 1, input().split()) a map(lambda x: int(x) - 1, input().split()) map lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x input().split() ().split () input split b if D2[a][b] == np.inf:
        print(-1)
    else:
        print(int(D2[a][b]) - 1) D2[a][b] == np.inf D2[a][b] [a] D2 a b np.inf np inf print(-1) print -1 print(int(D2[a][b]) - 1) print int(D2[a][b]) - 1 int(D2[a][b]) int D2[a][b] [a] D2 a b 1 a, b, c = map(int, input().split()) map(int, input().split()) a N,M,L = map(int,input().split()) map(int,input().split()) N D = floyd_warshall(G, directed=False) floyd_warshall(G, directed=False) D c = map(int, input().split()) map(int, input().split()) c G2 = np.full((N, N), np.inf) np.full((N, N), np.inf) G2 M,L = map(int,input().split()) map(int,input().split()) M G = np.full((N, N), np.inf) np.full((N, N), np.inf) G Q = int(input()) int(input()) Q L = map(int,input().split()) map(int,input().split()) L b = map(lambda x: int(x) - 1, input().split()) map(lambda x: int(x) - 1, input().split()) b b, c = map(int, input().split()) map(int, input().split()) b a, b = map(lambda x: int(x) - 1, input().split()) map(lambda x: int(x) - 1, input().split()) a D2 = floyd_warshall(G2, directed=False) floyd_warshall(G2, directed=False) D2
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

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

G = np.full((N, N), np.inf)
np.fill_diagonal(G, 0)
for _ in range(M):
    a, b, c = map(int, input().split())
    G[a-1][b-1] = G[b-1][a-1] = c
D = floyd_warshall(G, directed=False)

G2 = np.full((N, N), np.inf)
np.fill_diagonal(G2, 0)
G2[D <= L] = 1
D2 = floyd_warshall(G2, directed=False)

Q = int(input())
for _ in range(Q):
    a, b = map(lambda x: int(x) - 1, input().split())
    if D2[a][b] == np.inf:
        print(-1)
    else:
        print(int(D2[a][b]) - 1)
