from scipy.sparse.csgraph import floyd_warshall
 
# 下準備
N, M, L = map(int,input().split())
d = [[float("inf") for i in range(N)] for j in range(N)]
answer_d = [[float("inf") for i in range(N)] for j in range(N)]
for i in range(M):
    A, B, C = map(int,input().split())
    d[A-1][B-1] = d[B-1][A-1] = C
for i in range(N):
    d[i][i] = 0
 
# 燃料補給回数の最小値を求める
d = floyd_warshall(d)
for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            answer_d[i][j] = answer_d[j][i] = 1
d = floyd_warshall(answer_d)
 
# クエリを答える
Q = int(input())
answer = [-1]*Q
for i in range(Q):
    s, t = map(int,input().split())
    if d[s-1][t-1] != float("inf"):
        answer[i] = d[s-1][t-1]-1
 
for i in answer:
    print(i) 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 [float("inf") for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [float("inf") for i in range(N)] d = [[float("inf") for i in range(N)] for j in range(N)] d [[float("inf") for i in range(N)] for j in range(N)] [float("inf") for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [float("inf") for i in range(N)] answer_d = [[float("inf") for i in range(N)] for j in range(N)] answer_d [[float("inf") for i in range(N)] for j in range(N)] for i in range(M):
    A, B, C = map(int,input().split())
    d[A-1][B-1] = d[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 d[A-1][B-1] = d[B-1][A-1] = C d[A-1][B-1] [A-1] d A-1 A 1 B-1 B 1 C = d[B-1][A-1] = C d[B-1][A-1] [B-1] d B-1 B 1 A-1 A 1 C for i in range(N):
    d[i][i] = 0
 
# 燃料補給回数の最小値を求める i range(N) range N d[i][i] = 0 d[i][i] [i] d i i 0 d = floyd_warshall(d) d floyd_warshall(d) floyd_warshall d for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            answer_d[i][j] = answer_d[j][i] = 1 i range(N) range N for j in range(N):
        if d[i][j] <= L:
            answer_d[i][j] = answer_d[j][i] = 1 j range(N) range N if d[i][j] <= L:
            answer_d[i][j] = answer_d[j][i] = 1 d[i][j] <= L d[i][j] [i] d i j L answer_d[i][j] = answer_d[j][i] = 1 answer_d[i][j] [i] answer_d i j 1 = answer_d[j][i] = 1 answer_d[j][i] [j] answer_d j i 1 d = floyd_warshall(answer_d) d floyd_warshall(answer_d) floyd_warshall answer_d Q = int(input()) Q int(input()) int input() input answer = [-1]*Q answer [-1]*Q [-1] -1 Q for i in range(Q):
    s, t = map(int,input().split())
    if d[s-1][t-1] != float("inf"):
        answer[i] = d[s-1][t-1]-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 if d[s-1][t-1] != float("inf"):
        answer[i] = d[s-1][t-1]-1
  d[s-1][t-1] != float("inf") d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 float("inf") float "inf" answer[i] = d[s-1][t-1]-1 answer[i] answer i d[s-1][t-1]-1 d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 1 for i in answer:
    print(i) i answer print(i) print i Q = int(input()) int(input()) Q t = map(int,input().split()) map(int,input().split()) t d = floyd_warshall(d) floyd_warshall(d) d d = [[float("inf") for i in range(N)] for j in range(N)] [[float("inf") for i in range(N)] for j in range(N)] d s, t = map(int,input().split()) map(int,input().split()) s d = floyd_warshall(answer_d) floyd_warshall(answer_d) d N, M, L = map(int,input().split()) map(int,input().split()) N answer = [-1]*Q [-1]*Q answer C = map(int,input().split()) map(int,input().split()) C A, B, C = map(int,input().split()) map(int,input().split()) A B, C = map(int,input().split()) map(int,input().split()) B L = map(int,input().split()) map(int,input().split()) L answer_d = [[float("inf") for i in range(N)] for j in range(N)] [[float("inf") for i in range(N)] for j in range(N)] answer_d M, L = map(int,input().split()) map(int,input().split()) M
from scipy.sparse.csgraph import floyd_warshall
 
# 下準備
N, M, L = map(int,input().split())
d = [[float("inf") for i in range(N)] for j in range(N)]
answer_d = [[float("inf") for i in range(N)] for j in range(N)]
for i in range(M):
    A, B, C = map(int,input().split())
    d[A-1][B-1] = d[B-1][A-1] = C
for i in range(N):
    d[i][i] = 0
 
# 燃料補給回数の最小値を求める
d = floyd_warshall(d)
for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            answer_d[i][j] = answer_d[j][i] = 1
d = floyd_warshall(answer_d)
 
# クエリを答える
Q = int(input())
answer = [-1]*Q
for i in range(Q):
    s, t = map(int,input().split())
    if d[s-1][t-1] != float("inf"):
        answer[i] = d[s-1][t-1]-1
 
for i in answer:
    print(i)