from math import isinf
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix

INF = float('inf')

def main():
    N, M, L = list(map(int, input().split()))
    E = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        E[a - 1][b - 1] = c
        E[b - 1][a - 1] = c
    EE = shortest_path(csr_matrix(E))
    E = [[1 if EE[i][j] <= L else INF for j in range(N)] for i in range(N)]
    EE = shortest_path(csr_matrix(E))
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        x = EE[s - 1][t - 1]
        print(-1 if isinf(x) else int(x) - 1)
        

main() from math import isinf from scipy.sparse.csgraph import shortest_path from scipy.sparse import csr_matrix INF = float('inf') INF float('inf') float 'inf' def main():
    N, M, L = list(map(int, input().split()))
    E = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        E[a - 1][b - 1] = c
        E[b - 1][a - 1] = c
    EE = shortest_path(csr_matrix(E))
    E = [[1 if EE[i][j] <= L else INF for j in range(N)] for i in range(N)]
    EE = shortest_path(csr_matrix(E))
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        x = EE[s - 1][t - 1]
        print(-1 if isinf(x) else int(x) - 1)
         main N, M, L = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M L [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N E = [[INF] * N for _ in range(N)] E [[INF] * N for _ in range(N)] for _ in range(M):
        a, b, c = list(map(int, input().split()))
        E[a - 1][b - 1] = c
        E[b - 1][a - 1] = c
     _ range(M) range M a, b, c = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split b c E[a - 1][b - 1] = c E[a - 1][b - 1] [a - 1] E a - 1 a 1 b - 1 b 1 c E[b - 1][a - 1] = c E[b - 1][a - 1] [b - 1] E b - 1 b 1 a - 1 a 1 c EE = shortest_path(csr_matrix(E)) EE shortest_path(csr_matrix(E)) shortest_path csr_matrix(E) csr_matrix E [1 if EE[i][j] <= L else INF for j in range(N)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [1 if EE[i][j] <= L else INF for j in range(N)] E = [[1 if EE[i][j] <= L else INF for j in range(N)] for i in range(N)] E [[1 if EE[i][j] <= L else INF for j in range(N)] for i in range(N)] EE = shortest_path(csr_matrix(E)) EE shortest_path(csr_matrix(E)) shortest_path csr_matrix(E) csr_matrix E Q = int(input()) Q int(input()) int input() input for _ in range(Q):
        s, t = map(int, input().split())
        x = EE[s - 1][t - 1]
        print(-1 if isinf(x) else int(x) - 1)
         _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t x = EE[s - 1][t - 1] x EE[s - 1][t - 1] [s - 1] EE s - 1 s 1 t - 1 t 1 print(-1 if isinf(x) else int(x) - 1) print -1 if isinf(x) else int(x) - 1 isinf(x) isinf x -1 int(x) - 1 int(x) int x 1 main() main def main():
    N, M, L = list(map(int, input().split()))
    E = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        E[a - 1][b - 1] = c
        E[b - 1][a - 1] = c
    EE = shortest_path(csr_matrix(E))
    E = [[1 if EE[i][j] <= L else INF for j in range(N)] for i in range(N)]
    EE = shortest_path(csr_matrix(E))
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        x = EE[s - 1][t - 1]
        print(-1 if isinf(x) else int(x) - 1)
         def main():
    N, M, L = list(map(int, input().split()))
    E = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        E[a - 1][b - 1] = c
        E[b - 1][a - 1] = c
    EE = shortest_path(csr_matrix(E))
    E = [[1 if EE[i][j] <= L else INF for j in range(N)] for i in range(N)]
    EE = shortest_path(csr_matrix(E))
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        x = EE[s - 1][t - 1]
        print(-1 if isinf(x) else int(x) - 1)
         main INF = float('inf') float('inf') INF
from math import isinf
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix

INF = float('inf')

def main():
    N, M, L = list(map(int, input().split()))
    E = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        E[a - 1][b - 1] = c
        E[b - 1][a - 1] = c
    EE = shortest_path(csr_matrix(E))
    E = [[1 if EE[i][j] <= L else INF for j in range(N)] for i in range(N)]
    EE = shortest_path(csr_matrix(E))
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        x = EE[s - 1][t - 1]
        print(-1 if isinf(x) else int(x) - 1)
        

main()
