def io_tmp():

    global input

    import io, sys

    #f = io.StringIO(open(0).read())

    f = io.BytesIO(sys.stdin.buffer.read())

    input = f.readline



io_tmp()





from scipy.sparse.csgraph import floyd_warshall

import numpy as np



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

graph = [[float("inf")] * N for _ in range(N)]

for _ in range(M):

    s, t, w = map(int, input().split())

    if w <= L:

        graph[s-1][t-1] = graph[t-1][s-1] = w

dist = floyd_warshall(graph, directed=False)

graph = dist <= L

#np.fill_diagonal(graph, 0)

#graph[dist > L] = 0

dist = floyd_warshall(graph, directed=False)

dist[np.isinf(dist)] = 0

dist = dist.astype(int)



Q = int(input())

ans = []

for _ in range(Q):

    s, t = map(int, input().split())

    ans.append(dist[s-1][t-1] - 1)

print(*ans, sep='\n')

def io_tmp():

    global input

    import io, sys

    #f = io.StringIO(open(0).read())

    f = io.BytesIO(sys.stdin.buffer.read())

    input = f.readline



io_tmp()





from scipy.sparse.csgraph import floyd_warshall

import numpy as np



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

graph = [[float("inf")] * N for _ in range(N)]

for _ in range(M):

    s, t, w = map(int, input().split())

    if w <= L:

        graph[s-1][t-1] = graph[t-1][s-1] = w

dist = floyd_warshall(graph, directed=False)

graph = dist <= L

#np.fill_diagonal(graph, 0)

#graph[dist > L] = 0

dist = floyd_warshall(graph, directed=False)

dist[np.isinf(dist)] = 0

#dist = dist.astype(int)



Q = int(input())

ans = []

for _ in range(Q):

    s, t = map(int, input().split())

    ans.append(int(dist[s-1][t-1]) - 1)

print(*ans, sep='\n')

def io_tmp():
    global input
    import io, sys

    # f = io.StringIO(open(0).read())
    f = io.BytesIO(sys.stdin.buffer.read())
    input = f.readline


io_tmp()
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
graph = [[float("inf")] * N for _ in range(N)]
for _ in range(M):
    s, t, w = map(int, input().split())
    if w <= L:
        graph[s - 1][t - 1] = graph[t - 1][s - 1] = w
dist = floyd_warshall(graph, directed=False)
graph = dist <= L
# np.fill_diagonal(graph, 0)
# graph[dist > L] = 0
dist = floyd_warshall(graph, directed=False)
dist[np.isinf(dist)] = 0
dist = dist.astype(int)
Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(dist[s - 1][t - 1] - 1)
print(*ans, sep="\n")

def io_tmp():
    global input
    import io, sys

    # f = io.StringIO(open(0).read())
    f = io.BytesIO(sys.stdin.buffer.read())
    input = f.readline


io_tmp()
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
graph = [[float("inf")] * N for _ in range(N)]
for _ in range(M):
    s, t, w = map(int, input().split())
    if w <= L:
        graph[s - 1][t - 1] = graph[t - 1][s - 1] = w
dist = floyd_warshall(graph, directed=False)
graph = dist <= L
# np.fill_diagonal(graph, 0)
# graph[dist > L] = 0
dist = floyd_warshall(graph, directed=False)
dist[np.isinf(dist)] = 0
# dist = dist.astype(int)
Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(int(dist[s - 1][t - 1]) - 1)
print(*ans, sep="\n")

-dist = dist.astype(int) +# dist = dist.astype(int) -    ans.append(dist[s - 1][t - 1] - 1) +    ans.append(int(dist[s - 1][t - 1]) - 1)