import numpy as np

from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall



N, M, L = [int(_) for _ in input().split()]

ABC = [[int(_) for _ in input().split()] for _ in range(M)]

Q = int(eval(input()))

ST = [[int(_) for _ in input().split()] for _ in range(Q)]

edge = np.full((N, N), 10**10, dtype=int)

for a, b, c in ABC:

    if c <= L:

        edge[a - 1][b - 1] = edge[b - 1][a - 1] = c

G = csgraph_from_dense(edge, null_value=10**10)

D = floyd_warshall(G)

D = D <= L

E = floyd_warshall(D)

INF = float('inf')

for s, t in ST:

    d = E[s - 1][t - 1]

    if d == INF:

        d = 0

    print((int(d) - 1))

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

import numpy as np

from scipy.sparse.csgraph import floyd_warshall

from scipy.sparse import csr_matrix



N, M, L = [int(_) for _ in readline().split()]

ABCQST = np.array([int(_) for _ in read().split()], dtype=np.int64)

ABC = ABCQST[:3 * M]

ST = ABCQST[3 * M + 1:]

A, B, C = ABC[::3], ABC[1::3], ABC[2::3]

S, T = ST[::2], ST[1::2]

G = csr_matrix((C, (A, B)), shape=(N + 1, N + 1))

G2 = floyd_warshall(G, directed=0)

G3 = G2 <= L

G4 = floyd_warshall(G3, directed=0)

G4[G4 == 0] = 1

G4[G4 == np.inf] = 0

G4 -= 1

print(*G4[S, T].astype(np.int64), sep='\n')

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

N, M, L = [int(_) for _ in input().split()]
ABC = [[int(_) for _ in input().split()] for _ in range(M)]
Q = int(eval(input()))
ST = [[int(_) for _ in input().split()] for _ in range(Q)]
edge = np.full((N, N), 10**10, dtype=int)
for a, b, c in ABC:
    if c <= L:
        edge[a - 1][b - 1] = edge[b - 1][a - 1] = c
G = csgraph_from_dense(edge, null_value=10**10)
D = floyd_warshall(G)
D = D <= L
E = floyd_warshall(D)
INF = float("inf")
for s, t in ST:
    d = E[s - 1][t - 1]
    if d == INF:
        d = 0
    print((int(d) - 1))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

N, M, L = [int(_) for _ in readline().split()]
ABCQST = np.array([int(_) for _ in read().split()], dtype=np.int64)
ABC = ABCQST[: 3 * M]
ST = ABCQST[3 * M + 1 :]
A, B, C = ABC[::3], ABC[1::3], ABC[2::3]
S, T = ST[::2], ST[1::2]
G = csr_matrix((C, (A, B)), shape=(N + 1, N + 1))
G2 = floyd_warshall(G, directed=0)
G3 = G2 <= L
G4 = floyd_warshall(G3, directed=0)
G4[G4 == 0] = 1
G4[G4 == np.inf] = 0
G4 -= 1
print(*G4[S, T].astype(np.int64), sep="\n")

+import sys + +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines -from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall +from scipy.sparse.csgraph import floyd_warshall +from scipy.sparse import csr_matrix -N, M, L = [int(_) for _ in input().split()] -ABC = [[int(_) for _ in input().split()] for _ in range(M)] -Q = int(eval(input())) -ST = [[int(_) for _ in input().split()] for _ in range(Q)] -edge = np.full((N, N), 10**10, dtype=int) -for a, b, c in ABC: -    if c <= L: -        edge[a - 1][b - 1] = edge[b - 1][a - 1] = c -G = csgraph_from_dense(edge, null_value=10**10) -D = floyd_warshall(G) -D = D <= L -E = floyd_warshall(D) -INF = float("inf") -for s, t in ST: -    d = E[s - 1][t - 1] -    if d == INF: -        d = 0 -    print((int(d) - 1)) +N, M, L = [int(_) for _ in readline().split()] +ABCQST = np.array([int(_) for _ in read().split()], dtype=np.int64) +ABC = ABCQST[: 3 * M] +ST = ABCQST[3 * M + 1 :] +A, B, C = ABC[::3], ABC[1::3], ABC[2::3] +S, T = ST[::2], ST[1::2] +G = csr_matrix((C, (A, B)), shape=(N + 1, N + 1)) +G2 = floyd_warshall(G, directed=0) +G3 = G2 <= L +G4 = floyd_warshall(G3, directed=0) +G4[G4 == 0] = 1 +G4[G4 == np.inf] = 0 +G4 -= 1 +print(*G4[S, T].astype(np.int64), sep="\n")