import numpy as np
from scipy.sparse.csgraph import floyd_warshall


def main():
    N, M, L = map(int, input().split())
    graph = [[0] * N for _ in range(N)]
    for _ in range(M):
        s, t, w = map(int, input().split())
        if w <= L:
            graph[s-1][t-1] = graph[t-1][s-1] = w
    graph = floyd_warshall(graph, directed=False)
    graph = floyd_warshall(graph <= L, directed=False)
    graph[np.isinf(graph)] = 0

    Q = int(input())
    ans = []
    for _ in range(Q):
        s, t = map(int, input().split())
        ans.append(int(graph[s-1][t-1]) - 1)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main() import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall def main():
    N, M, L = map(int, input().split())
    graph = [[0] * N for _ in range(N)]
    for _ in range(M):
        s, t, w = map(int, input().split())
        if w <= L:
            graph[s-1][t-1] = graph[t-1][s-1] = w
    graph = floyd_warshall(graph, directed=False)
    graph = floyd_warshall(graph <= L, directed=False)
    graph[np.isinf(graph)] = 0

    Q = int(input())
    ans = []
    for _ in range(Q):
        s, t = map(int, input().split())
        ans.append(int(graph[s-1][t-1]) - 1)
    print(*ans, sep='\n') main N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [0] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [0] * N [0] 0 N graph = [[0] * N for _ in range(N)] graph [[0] * N for _ in range(N)] for _ in range(M):
        s, t, w = map(int, input().split())
        if w <= L:
            graph[s-1][t-1] = graph[t-1][s-1] = w
     _ range(M) range M s, t, w = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t w if w <= L:
            graph[s-1][t-1] = graph[t-1][s-1] = w
     w <= L w L graph[s-1][t-1] = graph[t-1][s-1] = w graph[s-1][t-1] [s-1] graph s-1 s 1 t-1 t 1 w = graph[t-1][s-1] = w graph[t-1][s-1] [t-1] graph t-1 t 1 s-1 s 1 w graph = floyd_warshall(graph, directed=False) graph floyd_warshall(graph, directed=False) floyd_warshall graph directed=False directed False graph = floyd_warshall(graph <= L, directed=False) graph floyd_warshall(graph <= L, directed=False) floyd_warshall graph <= L graph L directed=False directed False graph[np.isinf(graph)] = 0 graph[np.isinf(graph)] graph np.isinf(graph) np.isinf np isinf graph 0 Q = int(input()) Q int(input()) int input() input ans = [] ans [] for _ in range(Q):
        s, t = map(int, input().split())
        ans.append(int(graph[s-1][t-1]) - 1)
     _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t ans.append(int(graph[s-1][t-1]) - 1) ans.append ans append int(graph[s-1][t-1]) - 1 int(graph[s-1][t-1]) int graph[s-1][t-1] [s-1] graph s-1 s 1 t-1 t 1 1 print(*ans, sep='\n') print *ans ans sep='\n' sep '\n' if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N, M, L = map(int, input().split())
    graph = [[0] * N for _ in range(N)]
    for _ in range(M):
        s, t, w = map(int, input().split())
        if w <= L:
            graph[s-1][t-1] = graph[t-1][s-1] = w
    graph = floyd_warshall(graph, directed=False)
    graph = floyd_warshall(graph <= L, directed=False)
    graph[np.isinf(graph)] = 0

    Q = int(input())
    ans = []
    for _ in range(Q):
        s, t = map(int, input().split())
        ans.append(int(graph[s-1][t-1]) - 1)
    print(*ans, sep='\n') def main():
    N, M, L = map(int, input().split())
    graph = [[0] * N for _ in range(N)]
    for _ in range(M):
        s, t, w = map(int, input().split())
        if w <= L:
            graph[s-1][t-1] = graph[t-1][s-1] = w
    graph = floyd_warshall(graph, directed=False)
    graph = floyd_warshall(graph <= L, directed=False)
    graph[np.isinf(graph)] = 0

    Q = int(input())
    ans = []
    for _ in range(Q):
        s, t = map(int, input().split())
        ans.append(int(graph[s-1][t-1]) - 1)
    print(*ans, sep='\n') main
import numpy as np
from scipy.sparse.csgraph import floyd_warshall


def main():
    N, M, L = map(int, input().split())
    graph = [[0] * N for _ in range(N)]
    for _ in range(M):
        s, t, w = map(int, input().split())
        if w <= L:
            graph[s-1][t-1] = graph[t-1][s-1] = w
    graph = floyd_warshall(graph, directed=False)
    graph = floyd_warshall(graph <= L, directed=False)
    graph[np.isinf(graph)] = 0

    Q = int(input())
    ans = []
    for _ in range(Q):
        s, t = map(int, input().split())
        ans.append(int(graph[s-1][t-1]) - 1)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()
