import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

N, M, L = inpl()
graph = [[0]*N for _ in range(N)]
for i in range(M):
    A, B, C = inpl()
    if C <= L:
        graph[A-1][B-1] = C

Q = int(input())
ST = []
for _ in range(Q):
    s, t = inpl()
    s -= 1
    t -= 1
    ST.append((s, t))

distance = floyd_warshall(csr_matrix(graph), directed=False)
path = [[0]*N for _ in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        d = distance[i][j]
        if d <= L:
            path[i][j] = 1
ans = floyd_warshall(csr_matrix(path), directed=False)
for s, t in ST:
    if ans[s][t] == np.float('inf'):
        print(-1)
    else:
        print(int(ans[s][t]-1)) import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip inpl = lambda: list(map(int,input().split())) inpl lambda: list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split import numpy as np numpy from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall N, M, L = inpl() N inpl() inpl 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 i in range(M):
    A, B, C = inpl()
    if C <= L:
        graph[A-1][B-1] = C i range(M) range M A, B, C = inpl() A inpl() inpl B C if C <= L:
        graph[A-1][B-1] = C C <= L C L graph[A-1][B-1] = C graph[A-1][B-1] [A-1] graph A-1 A 1 B-1 B 1 C Q = int(input()) Q int(input()) int input() input ST = [] ST [] for _ in range(Q):
    s, t = inpl()
    s -= 1
    t -= 1
    ST.append((s, t)) _ range(Q) range Q s, t = inpl() s inpl() inpl t s -= 1 s 1 t -= 1 t 1 ST.append((s, t)) ST.append ST append (s, t) s t distance = floyd_warshall(csr_matrix(graph), directed=False) distance floyd_warshall(csr_matrix(graph), directed=False) floyd_warshall csr_matrix(graph) csr_matrix graph directed=False directed False [0]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [0]*N [0] 0 N path = [[0]*N for _ in range(N)] path [[0]*N for _ in range(N)] for i in range(N-1):
    for j in range(i+1,N):
        d = distance[i][j]
        if d <= L:
            path[i][j] = 1 i range(N-1) range N-1 N 1 for j in range(i+1,N):
        d = distance[i][j]
        if d <= L:
            path[i][j] = 1 j range(i+1,N) range i+1 i 1 N d = distance[i][j] d distance[i][j] [i] distance i j if d <= L:
            path[i][j] = 1 d <= L d L path[i][j] = 1 path[i][j] [i] path i j 1 ans = floyd_warshall(csr_matrix(path), directed=False) ans floyd_warshall(csr_matrix(path), directed=False) floyd_warshall csr_matrix(path) csr_matrix path directed=False directed False for s, t in ST:
    if ans[s][t] == np.float('inf'):
        print(-1)
    else:
        print(int(ans[s][t]-1)) s t ST if ans[s][t] == np.float('inf'):
        print(-1)
    else:
        print(int(ans[s][t]-1)) ans[s][t] == np.float('inf') ans[s][t] [s] ans s t np.float('inf') np.float np float 'inf' print(-1) print -1 print(int(ans[s][t]-1)) print int(ans[s][t]-1) int ans[s][t]-1 ans[s][t] [s] ans s t 1 input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input C = inpl() inpl() C B, C = inpl() inpl() B distance = floyd_warshall(csr_matrix(graph), directed=False) floyd_warshall(csr_matrix(graph), directed=False) distance L = inpl() inpl() L t = inpl() inpl() t ans = floyd_warshall(csr_matrix(path), directed=False) floyd_warshall(csr_matrix(path), directed=False) ans graph = [[0]*N for _ in range(N)] [[0]*N for _ in range(N)] graph Q = int(input()) int(input()) Q d = distance[i][j] distance[i][j] d inpl = lambda: list(map(int,input().split())) lambda: list(map(int,input().split())) inpl N, M, L = inpl() inpl() N path = [[0]*N for _ in range(N)] [[0]*N for _ in range(N)] path s -= 1 1 s t -= 1 1 t A, B, C = inpl() inpl() A ST = [] [] ST M, L = inpl() inpl() M s, t = inpl() inpl() s
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

N, M, L = inpl()
graph = [[0]*N for _ in range(N)]
for i in range(M):
    A, B, C = inpl()
    if C <= L:
        graph[A-1][B-1] = C

Q = int(input())
ST = []
for _ in range(Q):
    s, t = inpl()
    s -= 1
    t -= 1
    ST.append((s, t))

distance = floyd_warshall(csr_matrix(graph), directed=False)
path = [[0]*N for _ in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        d = distance[i][j]
        if d <= L:
            path[i][j] = 1
ans = floyd_warshall(csr_matrix(path), directed=False)
for s, t in ST:
    if ans[s][t] == np.float('inf'):
        print(-1)
    else:
        print(int(ans[s][t]-1))
