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

N, M, L = map(int, input().split())
graph = np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)])
graph2 = np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)])


for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c
dist = floyd_warshall(graph)

graph2[(dist <= L) & (dist != 0)] = 1
dist2 = floyd_warshall(graph2)
dist2[dist2 == float("inf")] = 0

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    print(int(dist2[s - 1, t - 1]) - 1)
 from scipy.sparse.csgraph import floyd_warshall import numpy as np numpy N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [0 if i == j else float("inf")
                   for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [0 if i == j else float("inf")
                   for i in range(N)] graph = np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)]) graph np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)]) np.array np array [[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)] [0 if i == j else float("inf")
                   for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [0 if i == j else float("inf")
                   for i in range(N)] graph2 = np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)]) graph2 np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)]) np.array np array [[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)] for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = 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 graph[a - 1][b - 1] = c graph[a - 1][b - 1] [a - 1] graph a - 1 a 1 b - 1 b 1 c graph[b - 1][a - 1] = c graph[b - 1][a - 1] [b - 1] graph b - 1 b 1 a - 1 a 1 c dist = floyd_warshall(graph) dist floyd_warshall(graph) floyd_warshall graph graph2[(dist <= L) & (dist != 0)] = 1 graph2[(dist <= L) & (dist != 0)] graph2 (dist <= L) & (dist != 0) dist <= L dist L dist != 0 dist 0 1 dist2 = floyd_warshall(graph2) dist2 floyd_warshall(graph2) floyd_warshall graph2 dist2[dist2 == float("inf")] = 0 dist2[dist2 == float("inf")] dist2 dist2 == float("inf") dist2 float("inf") float "inf" 0 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    print(int(dist2[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 print(int(dist2[s - 1, t - 1]) - 1) print int(dist2[s - 1, t - 1]) - 1 int(dist2[s - 1, t - 1]) int dist2[s - 1, t - 1] dist2 s - 1 s 1 1 a, b, c = map(int, input().split()) map(int, input().split()) a M, L = map(int, input().split()) map(int, input().split()) M c = map(int, input().split()) map(int, input().split()) c dist2 = floyd_warshall(graph2) floyd_warshall(graph2) dist2 graph2 = np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)]) np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)]) graph2 Q = int(input()) int(input()) Q N, M, L = map(int, input().split()) map(int, input().split()) N b, c = map(int, input().split()) map(int, input().split()) b s, t = map(int, input().split()) map(int, input().split()) s graph = np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)]) np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)]) graph t = map(int, input().split()) map(int, input().split()) t L = map(int, input().split()) map(int, input().split()) L dist = floyd_warshall(graph) floyd_warshall(graph) dist
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
graph = np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)])
graph2 = np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)])


for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c
dist = floyd_warshall(graph)

graph2[(dist <= L) & (dist != 0)] = 1
dist2 = floyd_warshall(graph2)
dist2[dist2 == float("inf")] = 0

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    print(int(dist2[s - 1, t - 1]) - 1)

