import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
INF = 10**12
N, M, L = map(int, input().split())

A = []; B = []; C = []
for i in range(M):
    a, b, c = map(int, input().split())
    A.append(a - 1); B.append(b - 1); C.append(c)
A = np.array(A); B = np.array(B); C = np.array(C)

graph = csr_matrix((C, (A, B)), (N, N))
d = floyd_warshall(graph, directed=False)

d[d <= L] = 1
d[d > L] = INF

d = floyd_warshall(d, directed=False)

Q = int(input())
for i in range(Q):
    s, t = map(int, input().split())
    if d[s - 1][t - 1] != INF:
        print(int(d[s - 1][t - 1]) - 1)
    else:
        print(- 1) import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix 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 A = [] A [] B = [] B [] C = [] C [] for i in range(M):
    a, b, c = map(int, input().split())
    A.append(a - 1); B.append(b - 1); C.append(c) i 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.append(a - 1) A.append A append a - 1 a 1 B.append(b - 1) B.append B append b - 1 b 1 C.append(c) C.append C append c A = np.array(A) A np.array(A) np.array np array A B = np.array(B) B np.array(B) np.array np array B C = np.array(C) C np.array(C) np.array np array C graph = csr_matrix((C, (A, B)), (N, N)) graph csr_matrix((C, (A, B)), (N, N)) csr_matrix (C, (A, B)) C (A, B) A B (N, N) N N d = floyd_warshall(graph, directed=False) d floyd_warshall(graph, directed=False) floyd_warshall graph directed=False directed False d[d <= L] = 1 d[d <= L] d d <= L d L 1 d[d > L] = INF d[d > L] d d > L d L INF d = floyd_warshall(d, directed=False) d floyd_warshall(d, directed=False) floyd_warshall d directed=False directed False Q = int(input()) Q int(input()) int input() input for i in range(Q):
    s, t = map(int, input().split())
    if d[s - 1][t - 1] != INF:
        print(int(d[s - 1][t - 1]) - 1)
    else:
        print(- 1) i range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if d[s - 1][t - 1] != INF:
        print(int(d[s - 1][t - 1]) - 1)
    else:
        print(- 1) d[s - 1][t - 1] != INF d[s - 1][t - 1] [s - 1] d s - 1 s 1 t - 1 t 1 INF print(int(d[s - 1][t - 1]) - 1) print int(d[s - 1][t - 1]) - 1 int(d[s - 1][t - 1]) int d[s - 1][t - 1] [s - 1] d s - 1 s 1 t - 1 t 1 1 print(- 1) print - 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 A = np.array(A) np.array(A) A c = map(int, input().split()) map(int, input().split()) c d = floyd_warshall(d, directed=False) floyd_warshall(d, directed=False) d s, t = map(int, input().split()) map(int, input().split()) s INF = 10**12 10**12 INF M, L = map(int, input().split()) map(int, input().split()) M Q = int(input()) int(input()) Q t = map(int, input().split()) map(int, input().split()) t A = [] [] A d = floyd_warshall(graph, directed=False) floyd_warshall(graph, directed=False) d B = [] [] B graph = csr_matrix((C, (A, B)), (N, N)) csr_matrix((C, (A, B)), (N, N)) graph C = [] [] C L = map(int, input().split()) map(int, input().split()) L C = np.array(C) np.array(C) C B = np.array(B) np.array(B) B b, c = map(int, input().split()) map(int, input().split()) b
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
INF = 10**12
N, M, L = map(int, input().split())

A = []; B = []; C = []
for i in range(M):
    a, b, c = map(int, input().split())
    A.append(a - 1); B.append(b - 1); C.append(c)
A = np.array(A); B = np.array(B); C = np.array(C)

graph = csr_matrix((C, (A, B)), (N, N))
d = floyd_warshall(graph, directed=False)

d[d <= L] = 1
d[d > L] = INF

d = floyd_warshall(d, directed=False)

Q = int(input())
for i in range(Q):
    s, t = map(int, input().split())
    if d[s - 1][t - 1] != INF:
        print(int(d[s - 1][t - 1]) - 1)
    else:
        print(- 1)