from scipy.sparse.csgraph import floyd_warshall

# ダイクストラではなくワーシャルフロイドで解く
N, M, L = map(int, input().split())
# graph = [[] for _ in range(N)]
distant = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    if c > L:
        continue
    distant[a][b] = c
    distant[b][a] = c

distant = floyd_warshall(distant)
another = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if distant[i][j] <= L:  # 行けるところまでいくという印象
            another[i][j] = 1
another = floyd_warshall(another)
Q = int(input())
for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    if another[s][t] == float('inf'):
        print(-1)
        continue
    print(int(another[s][t])-1)
    # if distant[s][t] == float('inf'):
    #     print(-1)
    #     continue
    # print(int(distant[s][t])//L + min(1, int(distant[s][t]) % L) - 1)
# 燃料が4で
# 1 -> 4 -> 2
# のとき、距離は7だから一見すると補給回数は1で良さそうだけど、実は2回必要
# 今、２点間の最小距離を求めておいて、もう一つのグラフは「最短距離がL以下の2点に辺(重み1)を張る」 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')]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [float('inf')]*N [float('inf')] float('inf') float 'inf' N distant = [[float('inf')]*N for _ in range(N)] distant [[float('inf')]*N for _ in range(N)] for _ in range(M):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    if c > L:
        continue
    distant[a][b] = c
    distant[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, b = a-1, b-1 a a-1 a 1 b b-1 b 1 if c > L:
        continue
     c > L c L continue distant[a][b] = c distant[a][b] [a] distant a b c distant[b][a] = c distant[b][a] [b] distant b a c distant = floyd_warshall(distant) distant floyd_warshall(distant) floyd_warshall distant [float('inf')]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [float('inf')]*N [float('inf')] float('inf') float 'inf' N another = [[float('inf')]*N for _ in range(N)] another [[float('inf')]*N for _ in range(N)] for i in range(N):
    for j in range(N):
        if distant[i][j] <= L:  # 行けるところまでいくという印象
            another[i][j] = 1 i range(N) range N for j in range(N):
        if distant[i][j] <= L:  # 行けるところまでいくという印象
            another[i][j] = 1 j range(N) range N if distant[i][j] <= L:  # 行けるところまでいくという印象
            another[i][j] = 1 distant[i][j] <= L distant[i][j] [i] distant i j L another[i][j] = 1 another[i][j] [i] another i j 1 another = floyd_warshall(another) another floyd_warshall(another) floyd_warshall another Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    if another[s][t] == float('inf'):
        print(-1)
        continue
    print(int(another[s][t])-1)
    # if distant[s][t] == float('inf'):
    #     print(-1)
    #     continue
    # print(int(distant[s][t])//L + min(1, int(distant[s][t]) % L) - 1)
# 燃料が4で
# 1 -> 4 -> 2
# のとき、距離は7だから一見すると補給回数は1で良さそうだけど、実は2回必要
# 今、２点間の最小距離を求めておいて、もう一つのグラフは「最短距離がL以下の2点に辺(重み1)を張る」 _ range(Q) range Q s, t = map(lambda x: int(x)-1, input().split()) s map(lambda x: int(x)-1, input().split()) map lambda x: int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split t if another[s][t] == float('inf'):
        print(-1)
        continue
     another[s][t] == float('inf') another[s][t] [s] another s t float('inf') float 'inf' print(-1) print -1 continue print(int(another[s][t])-1) print int(another[s][t])-1 int(another[s][t]) int another[s][t] [s] another s t 1 M, L = map(int, input().split()) map(int, input().split()) M Q = int(input()) int(input()) Q another = [[float('inf')]*N for _ in range(N)] [[float('inf')]*N for _ in range(N)] another t = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) t s, t = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) s a, b, c = map(int, input().split()) map(int, input().split()) a b = a-1, b-1 b-1 b b, c = map(int, input().split()) map(int, input().split()) b distant = [[float('inf')]*N for _ in range(N)] [[float('inf')]*N for _ in range(N)] distant another = floyd_warshall(another) floyd_warshall(another) another distant = floyd_warshall(distant) floyd_warshall(distant) distant a, b = a-1, b-1 a-1 a L = map(int, input().split()) map(int, input().split()) L c = map(int, input().split()) map(int, input().split()) c N, M, L = map(int, input().split()) map(int, input().split()) N
from scipy.sparse.csgraph import floyd_warshall

# ダイクストラではなくワーシャルフロイドで解く
N, M, L = map(int, input().split())
# graph = [[] for _ in range(N)]
distant = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    if c > L:
        continue
    distant[a][b] = c
    distant[b][a] = c

distant = floyd_warshall(distant)
another = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if distant[i][j] <= L:  # 行けるところまでいくという印象
            another[i][j] = 1
another = floyd_warshall(another)
Q = int(input())
for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    if another[s][t] == float('inf'):
        print(-1)
        continue
    print(int(another[s][t])-1)
    # if distant[s][t] == float('inf'):
    #     print(-1)
    #     continue
    # print(int(distant[s][t])//L + min(1, int(distant[s][t]) % L) - 1)
# 燃料が4で
# 1 -> 4 -> 2
# のとき、距離は7だから一見すると補給回数は1で良さそうだけど、実は2回必要
# 今、２点間の最小距離を求めておいて、もう一つのグラフは「最短距離がL以下の2点に辺(重み1)を張る」
