from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())

G = [list(map(int, input().split())) for _ in range(M)]
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]

# neighborhood graph
nei_graph = [[0] * N for _ in range(N)]
for a, b, c in G:
    nei_graph[a - 1][b - 1] = c
    nei_graph[b - 1][a - 1] = c

# Warshall Floyd
nei_graph = floyd_warshall(nei_graph)

# 1 if distance is less than L
for i in range(N):
    for j in range(N):
        if nei_graph[i][j] <= L:
            nei_graph[i][j] = 1
        else:
            nei_graph[i][j] = 0

nei_graph = floyd_warshall(nei_graph)

for start, end in Query:
    if nei_graph[start - 1][end - 1] - 1 == float('inf'):
        print(-1)
    else:
        print(int(nei_graph[start - 1][end - 1] - 1)) from scipy.sparse.csgraph import floyd_warshall N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L list(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split G = [list(map(int, input().split())) for _ in range(M)] G [list(map(int, input().split())) for _ in range(M)] Q = int(input()) Q int(input()) int input() input list(map(int, input().split())) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split Query = [list(map(int, input().split())) for _ in range(Q)] Query [list(map(int, input().split())) for _ in range(Q)] [0] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [0] * N [0] 0 N nei_graph = [[0] * N for _ in range(N)] nei_graph [[0] * N for _ in range(N)] for a, b, c in G:
    nei_graph[a - 1][b - 1] = c
    nei_graph[b - 1][a - 1] = c

# Warshall Floyd a b c G nei_graph[a - 1][b - 1] = c nei_graph[a - 1][b - 1] [a - 1] nei_graph a - 1 a 1 b - 1 b 1 c nei_graph[b - 1][a - 1] = c nei_graph[b - 1][a - 1] [b - 1] nei_graph b - 1 b 1 a - 1 a 1 c nei_graph = floyd_warshall(nei_graph) nei_graph floyd_warshall(nei_graph) floyd_warshall nei_graph for i in range(N):
    for j in range(N):
        if nei_graph[i][j] <= L:
            nei_graph[i][j] = 1
        else:
            nei_graph[i][j] = 0 i range(N) range N for j in range(N):
        if nei_graph[i][j] <= L:
            nei_graph[i][j] = 1
        else:
            nei_graph[i][j] = 0 j range(N) range N if nei_graph[i][j] <= L:
            nei_graph[i][j] = 1
        else:
            nei_graph[i][j] = 0 nei_graph[i][j] <= L nei_graph[i][j] [i] nei_graph i j L nei_graph[i][j] = 1 nei_graph[i][j] [i] nei_graph i j 1 nei_graph[i][j] = 0 nei_graph[i][j] [i] nei_graph i j 0 nei_graph = floyd_warshall(nei_graph) nei_graph floyd_warshall(nei_graph) floyd_warshall nei_graph for start, end in Query:
    if nei_graph[start - 1][end - 1] - 1 == float('inf'):
        print(-1)
    else:
        print(int(nei_graph[start - 1][end - 1] - 1)) start end Query if nei_graph[start - 1][end - 1] - 1 == float('inf'):
        print(-1)
    else:
        print(int(nei_graph[start - 1][end - 1] - 1)) nei_graph[start - 1][end - 1] - 1 == float('inf') nei_graph[start - 1][end - 1] - 1 nei_graph[start - 1][end - 1] [start - 1] nei_graph start - 1 start 1 end - 1 end 1 1 float('inf') float 'inf' print(-1) print -1 print(int(nei_graph[start - 1][end - 1] - 1)) print int(nei_graph[start - 1][end - 1] - 1) int nei_graph[start - 1][end - 1] - 1 nei_graph[start - 1][end - 1] [start - 1] nei_graph start - 1 start 1 end - 1 end 1 1 N, M, L = map(int, input().split()) map(int, input().split()) N L = map(int, input().split()) map(int, input().split()) L nei_graph = floyd_warshall(nei_graph) floyd_warshall(nei_graph) nei_graph M, L = map(int, input().split()) map(int, input().split()) M Q = int(input()) int(input()) Q nei_graph = floyd_warshall(nei_graph) floyd_warshall(nei_graph) nei_graph Query = [list(map(int, input().split())) for _ in range(Q)] [list(map(int, input().split())) for _ in range(Q)] Query nei_graph = [[0] * N for _ in range(N)] [[0] * N for _ in range(N)] nei_graph G = [list(map(int, input().split())) for _ in range(M)] [list(map(int, input().split())) for _ in range(M)] G
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())

G = [list(map(int, input().split())) for _ in range(M)]
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]

# neighborhood graph
nei_graph = [[0] * N for _ in range(N)]
for a, b, c in G:
    nei_graph[a - 1][b - 1] = c
    nei_graph[b - 1][a - 1] = c

# Warshall Floyd
nei_graph = floyd_warshall(nei_graph)

# 1 if distance is less than L
for i in range(N):
    for j in range(N):
        if nei_graph[i][j] <= L:
            nei_graph[i][j] = 1
        else:
            nei_graph[i][j] = 0

nei_graph = floyd_warshall(nei_graph)

for start, end in Query:
    if nei_graph[start - 1][end - 1] - 1 == float('inf'):
        print(-1)
    else:
        print(int(nei_graph[start - 1][end - 1] - 1))