import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

n, m, l = map(int, input().split())
abc = []
for _ in range(m):
    abc.append(map(int, input().split()))
q = int(input())
st = []
for _ in range(q):
    st.append(map(int, input().split()))

adjacency_matrix = np.zeros((n, n))
for a, b, c in abc:
    adjacency_matrix[a-1, b-1] = c
    adjacency_matrix[b-1, a-1] = c

shotest = dijkstra(adjacency_matrix)
fuel_once = np.where(shotest <= l, 1, 0)
fuel_times = dijkstra(fuel_once-np.eye(n))

for s, t in st:
    ans = fuel_times[s-1][t-1]
    if np.isinf(ans):
        print(-1)
    else:
        print(int(ans) - 1) import numpy as np numpy from scipy.sparse import csr_matrix from scipy.sparse.csgraph import dijkstra n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l abc = [] abc [] for _ in range(m):
    abc.append(map(int, input().split())) _ range(m) range m abc.append(map(int, input().split())) abc.append abc append map(int, input().split()) map int input().split() ().split () input split q = int(input()) q int(input()) int input() input st = [] st [] for _ in range(q):
    st.append(map(int, input().split())) _ range(q) range q st.append(map(int, input().split())) st.append st append map(int, input().split()) map int input().split() ().split () input split adjacency_matrix = np.zeros((n, n)) adjacency_matrix np.zeros((n, n)) np.zeros np zeros (n, n) n n for a, b, c in abc:
    adjacency_matrix[a-1, b-1] = c
    adjacency_matrix[b-1, a-1] = c a b c abc adjacency_matrix[a-1, b-1] = c adjacency_matrix[a-1, b-1] adjacency_matrix a-1 a 1 c adjacency_matrix[b-1, a-1] = c adjacency_matrix[b-1, a-1] adjacency_matrix b-1 b 1 c shotest = dijkstra(adjacency_matrix) shotest dijkstra(adjacency_matrix) dijkstra adjacency_matrix fuel_once = np.where(shotest <= l, 1, 0) fuel_once np.where(shotest <= l, 1, 0) np.where np where shotest <= l shotest l 1 0 fuel_times = dijkstra(fuel_once-np.eye(n)) fuel_times dijkstra(fuel_once-np.eye(n)) dijkstra fuel_once-np.eye(n) fuel_once np.eye(n) np.eye np eye n for s, t in st:
    ans = fuel_times[s-1][t-1]
    if np.isinf(ans):
        print(-1)
    else:
        print(int(ans) - 1) s t st ans = fuel_times[s-1][t-1] ans fuel_times[s-1][t-1] [s-1] fuel_times s-1 s 1 t-1 t 1 if np.isinf(ans):
        print(-1)
    else:
        print(int(ans) - 1) np.isinf(ans) np.isinf np isinf ans print(-1) print -1 print(int(ans) - 1) print int(ans) - 1 int(ans) int ans 1 fuel_once = np.where(shotest <= l, 1, 0) np.where(shotest <= l, 1, 0) fuel_once fuel_times = dijkstra(fuel_once-np.eye(n)) dijkstra(fuel_once-np.eye(n)) fuel_times st = [] [] st ans = fuel_times[s-1][t-1] fuel_times[s-1][t-1] ans adjacency_matrix = np.zeros((n, n)) np.zeros((n, n)) adjacency_matrix m, l = map(int, input().split()) map(int, input().split()) m q = int(input()) int(input()) q shotest = dijkstra(adjacency_matrix) dijkstra(adjacency_matrix) shotest n, m, l = map(int, input().split()) map(int, input().split()) n l = map(int, input().split()) map(int, input().split()) l abc = [] [] abc
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

n, m, l = map(int, input().split())
abc = []
for _ in range(m):
    abc.append(map(int, input().split()))
q = int(input())
st = []
for _ in range(q):
    st.append(map(int, input().split()))

adjacency_matrix = np.zeros((n, n))
for a, b, c in abc:
    adjacency_matrix[a-1, b-1] = c
    adjacency_matrix[b-1, a-1] = c

shotest = dijkstra(adjacency_matrix)
fuel_once = np.where(shotest <= l, 1, 0)
fuel_times = dijkstra(fuel_once-np.eye(n))

for s, t in st:
    ans = fuel_times[s-1][t-1]
    if np.isinf(ans):
        print(-1)
    else:
        print(int(ans) - 1)
