

from scipy.sparse.csgraph import floyd_warshall

import numpy as np



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

graph = np.full((N, N), 10 ** 10)

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

graph = floyd_warshall(graph, directed=False)

graph = floyd_warshall(graph <= L, directed=False)

graph[np.isinf(graph)] = 0



Q = int(input())

ans = []

for _ in range(Q):

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

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

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

def use_fast_io():

    global input

    import io

    import sys

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

    input = f.readline

use_fast_io()

 

 

from scipy.sparse.csgraph import floyd_warshall

import numpy as np

 

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

graph = np.full((N, N), 10**10)

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

graph = floyd_warshall(graph, directed=False)

graph = floyd_warshall(graph <= L, directed=False)

graph[np.isinf(graph)] = 0

 

Q = int(input())

ans = []

for _ in range(Q):

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

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

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

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

N, M, L = map(int, input().split())
graph = np.full((N, N), 10**10)
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
graph = floyd_warshall(graph, directed=False)
graph = floyd_warshall(graph <= L, directed=False)
graph[np.isinf(graph)] = 0
Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(int(graph[s - 1][t - 1]) - 1)
print(*ans, sep="\n")

def use_fast_io():
    global input
    import io
    import sys

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


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

N, M, L = map(int, input().split())
graph = np.full((N, N), 10**10)
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
graph = floyd_warshall(graph, directed=False)
graph = floyd_warshall(graph <= L, directed=False)
graph[np.isinf(graph)] = 0
Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(int(graph[s - 1][t - 1]) - 1)
print(*ans, sep="\n")

+def use_fast_io(): +    global input +    import io +    import sys + +    f = io.BytesIO(sys.stdin.buffer.read()) +    input = f.readline + + +use_fast_io()