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

n, m, l = map(int, input().split())
INF = 1 << 60

# 距離のmatrixを作る
dist = [[INF] * n for _ in range(n)]

# 対角行列の成分は０
for i in range(n):
    dist[i][i] = 0

# 燃料の最大値より小さい場合に辺が張れる
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    if c > l:
        continue
    dist[a][b] = c
    dist[b][a] = c

# 全点間の最短距離を求める
dist = floyd_warshall(csr_matrix(dist))

# 初期状態を１にする。燃料が足りない経路は迂回したいのでINFを置いておく
dist2 = np.full_like(dist, 1)
dist2[np.where(dist > l)] = INF

# 足し込むことで何回給油するべきかがわかる
dist2 = floyd_warshall(dist2, directed=False)
dist2 = dist2.astype(int)

# 無限大の経路は辿れない。-1を出力したいので０を置いていく
dist2[dist2 == INF] = 0

q = int(input())

# 初期状態を１としているので、１を引いて答えとする
ans = []
for _ in range(q):
    s, t = map(int, input().split())
    ans.append(dist2[s - 1, t - 1] - 1)

print(*ans, sep="\n") import numpy as np numpy from scipy.sparse import csr_matrix 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 INF = 1 << 60 INF 1 << 60 1 60 [INF] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF] * n [INF] INF n dist = [[INF] * n for _ in range(n)] dist [[INF] * n for _ in range(n)] for i in range(n):
    dist[i][i] = 0

# 燃料の最大値より小さい場合に辺が張れる i range(n) range n dist[i][i] = 0 dist[i][i] [i] dist i i 0 for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    if c > l:
        continue
    dist[a][b] = c
    dist[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 if c > l:
        continue
     c > l c l continue dist[a][b] = c dist[a][b] [a] dist a b c dist[b][a] = c dist[b][a] [b] dist b a c dist = floyd_warshall(csr_matrix(dist)) dist floyd_warshall(csr_matrix(dist)) floyd_warshall csr_matrix(dist) csr_matrix dist dist2 = np.full_like(dist, 1) dist2 np.full_like(dist, 1) np.full_like np full_like dist 1 dist2[np.where(dist > l)] = INF dist2[np.where(dist > l)] dist2 np.where(dist > l) np.where np where dist > l dist l INF dist2 = floyd_warshall(dist2, directed=False) dist2 floyd_warshall(dist2, directed=False) floyd_warshall dist2 directed=False directed False dist2 = dist2.astype(int) dist2 dist2.astype(int) dist2.astype dist2 astype int dist2[dist2 == INF] = 0 dist2[dist2 == INF] dist2 dist2 == INF dist2 INF 0 q = int(input()) q int(input()) int input() input ans = [] ans [] for _ in range(q):
    s, t = map(int, input().split())
    ans.append(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 ans.append(dist2[s - 1, t - 1] - 1) ans.append ans append dist2[s - 1, t - 1] - 1 dist2[s - 1, t - 1] dist2 s - 1 s 1 1 print(*ans, sep="\n") print *ans ans sep="\n" sep "\n" n, m, l = map(int, input().split()) map(int, input().split()) n dist2 = np.full_like(dist, 1) np.full_like(dist, 1) dist2 ans = [] [] ans dist2 = floyd_warshall(dist2, directed=False) floyd_warshall(dist2, directed=False) dist2 q = int(input()) int(input()) q INF = 1 << 60 1 << 60 INF dist2 = dist2.astype(int) dist2.astype(int) dist2 a, b, c = map(int, input().split()) map(int, input().split()) a m, l = map(int, input().split()) map(int, input().split()) m dist = floyd_warshall(csr_matrix(dist)) floyd_warshall(csr_matrix(dist)) dist dist = [[INF] * n for _ in range(n)] [[INF] * n for _ in range(n)] dist b, c = map(int, input().split()) map(int, input().split()) b c = map(int, input().split()) map(int, input().split()) c a -= 1 1 a b -= 1 1 b s, t = map(int, input().split()) map(int, input().split()) s l = map(int, input().split()) map(int, input().split()) l t = map(int, input().split()) map(int, input().split()) t
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

n, m, l = map(int, input().split())
INF = 1 << 60

# 距離のmatrixを作る
dist = [[INF] * n for _ in range(n)]

# 対角行列の成分は０
for i in range(n):
    dist[i][i] = 0

# 燃料の最大値より小さい場合に辺が張れる
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    if c > l:
        continue
    dist[a][b] = c
    dist[b][a] = c

# 全点間の最短距離を求める
dist = floyd_warshall(csr_matrix(dist))

# 初期状態を１にする。燃料が足りない経路は迂回したいのでINFを置いておく
dist2 = np.full_like(dist, 1)
dist2[np.where(dist > l)] = INF

# 足し込むことで何回給油するべきかがわかる
dist2 = floyd_warshall(dist2, directed=False)
dist2 = dist2.astype(int)

# 無限大の経路は辿れない。-1を出力したいので０を置いていく
dist2[dist2 == INF] = 0

q = int(input())

# 初期状態を１としているので、１を引いて答えとする
ans = []
for _ in range(q):
    s, t = map(int, input().split())
    ans.append(dist2[s - 1, t - 1] - 1)

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