from scipy.sparse.csgraph import floyd_warshall

# ダイクストラを二回行う
N, M, L = map(int, input().split())
graph = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c

graph = floyd_warshall(graph)
another = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if graph[i][j] <= L:
            another[i][j] = 1
another = floyd_warshall(another)
Q = int(input())
for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    if another[s][t] == float('inf'):
        print(-1)
    else:
        print(int(another[s][t])-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 [float('inf')]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [float('inf')]*N [float('inf')] float('inf') float 'inf' N graph = [[float('inf')]*N for _ in range(N)] graph [[float('inf')]*N for _ in range(N)] for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c _ range(M) range M a, b, c = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b c a -= 1 a 1 b -= 1 b 1 graph[a][b] = c graph[a][b] [a] graph a b c graph[b][a] = c graph[b][a] [b] graph b a c graph = floyd_warshall(graph) graph floyd_warshall(graph) floyd_warshall graph [float('inf')]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [float('inf')]*N [float('inf')] float('inf') float 'inf' N another = [[float('inf')]*N for _ in range(N)] another [[float('inf')]*N for _ in range(N)] for i in range(N):
    for j in range(N):
        if graph[i][j] <= L:
            another[i][j] = 1 i range(N) range N for j in range(N):
        if graph[i][j] <= L:
            another[i][j] = 1 j range(N) range N if graph[i][j] <= L:
            another[i][j] = 1 graph[i][j] <= L graph[i][j] [i] graph i j L another[i][j] = 1 another[i][j] [i] another i j 1 another = floyd_warshall(another) another floyd_warshall(another) floyd_warshall another Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    if another[s][t] == float('inf'):
        print(-1)
    else:
        print(int(another[s][t])-1) _ range(Q) range Q s, t = map(lambda x: int(x)-1, input().split()) s map(lambda x: int(x)-1, input().split()) map lambda x: int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split t if another[s][t] == float('inf'):
        print(-1)
    else:
        print(int(another[s][t])-1) another[s][t] == float('inf') another[s][t] [s] another s t float('inf') float 'inf' print(-1) print -1 print(int(another[s][t])-1) print int(another[s][t])-1 int(another[s][t]) int another[s][t] [s] another s t 1 N, M, L = map(int, input().split()) map(int, input().split()) N graph = [[float('inf')]*N for _ in range(N)] [[float('inf')]*N for _ in range(N)] graph graph = floyd_warshall(graph) floyd_warshall(graph) graph b, c = map(int, input().split()) map(int, input().split()) b c = map(int, input().split()) map(int, input().split()) c another = floyd_warshall(another) floyd_warshall(another) another M, L = map(int, input().split()) map(int, input().split()) M a, b, c = map(int, input().split()) map(int, input().split()) a Q = int(input()) int(input()) Q t = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) t a -= 1 1 a s, t = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) s b -= 1 1 b another = [[float('inf')]*N for _ in range(N)] [[float('inf')]*N for _ in range(N)] another L = map(int, input().split()) map(int, input().split()) L
from scipy.sparse.csgraph import floyd_warshall

# ダイクストラを二回行う
N, M, L = map(int, input().split())
graph = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c

graph = floyd_warshall(graph)
another = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if graph[i][j] <= L:
            another[i][j] = 1
another = floyd_warshall(another)
Q = int(input())
for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    if another[s][t] == float('inf'):
        print(-1)
    else:
        print(int(another[s][t])-1)
