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

N, M, L = map(int, input().split())
inf = 10**9 + 1
dist = [[inf] * N for i in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    dist[A-1][B-1] = dist[B-1][A-1] = C

dist = floyd_warshall(dist, directed=False)
dist = np.where(dist <= L, 1, inf)
dist = floyd_warshall(dist, directed=False)
dist = np.where(dist < inf, dist-1, -1)

Q = int(input())
for i in range(Q):
    s, t = map(int, input().split())
    print(int(dist[s-1, t-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 inf = 10**9 + 1 inf 10**9 + 1 10**9 10 9 1 [inf] * N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [inf] * N [inf] inf N dist = [[inf] * N for i in range(N)] dist [[inf] * N for i in range(N)] for i in range(M):
    A, B, C = map(int, input().split())
    dist[A-1][B-1] = dist[B-1][A-1] = C i 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 dist[A-1][B-1] = dist[B-1][A-1] = C dist[A-1][B-1] [A-1] dist A-1 A 1 B-1 B 1 C = dist[B-1][A-1] = C dist[B-1][A-1] [B-1] dist B-1 B 1 A-1 A 1 C dist = floyd_warshall(dist, directed=False) dist floyd_warshall(dist, directed=False) floyd_warshall dist directed=False directed False dist = np.where(dist <= L, 1, inf) dist np.where(dist <= L, 1, inf) np.where np where dist <= L dist L 1 inf dist = floyd_warshall(dist, directed=False) dist floyd_warshall(dist, directed=False) floyd_warshall dist directed=False directed False dist = np.where(dist < inf, dist-1, -1) dist np.where(dist < inf, dist-1, -1) np.where np where dist < inf dist inf dist-1 dist 1 -1 Q = int(input()) Q int(input()) int input() input for i in range(Q):
    s, t = map(int, input().split())
    print(int(dist[s-1, t-1])) i 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(dist[s-1, t-1])) print int(dist[s-1, t-1]) int dist[s-1, t-1] dist s-1 s 1 M, L = map(int, input().split()) map(int, input().split()) M B, C = map(int, input().split()) map(int, input().split()) B t = map(int, input().split()) map(int, input().split()) t dist = np.where(dist <= L, 1, inf) np.where(dist <= L, 1, inf) dist L = map(int, input().split()) map(int, input().split()) L A, B, C = map(int, input().split()) map(int, input().split()) A dist = [[inf] * N for i in range(N)] [[inf] * N for i in range(N)] dist dist = floyd_warshall(dist, directed=False) floyd_warshall(dist, directed=False) dist C = map(int, input().split()) map(int, input().split()) C s, t = map(int, input().split()) map(int, input().split()) s dist = floyd_warshall(dist, directed=False) floyd_warshall(dist, directed=False) dist N, M, L = map(int, input().split()) map(int, input().split()) N inf = 10**9 + 1 10**9 + 1 inf dist = np.where(dist < inf, dist-1, -1) np.where(dist < inf, dist-1, -1) dist Q = int(input()) int(input()) Q
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
inf = 10**9 + 1
dist = [[inf] * N for i in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    dist[A-1][B-1] = dist[B-1][A-1] = C

dist = floyd_warshall(dist, directed=False)
dist = np.where(dist <= L, 1, inf)
dist = floyd_warshall(dist, directed=False)
dist = np.where(dist < inf, dist-1, -1)

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