
N, M, L = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]
Q = int(input())
Y = [list(map(int, input().split())) for _ in range(Q)]

INF = 10 ** 9 + 7
graph = [[INF] * N for _ in range(N)]
count = [[INF] * N for _ in range(N)]
for i in range(N):
    graph[i][i] = 0
    count[i][i] = 0

for a, b, c in X:
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

for i in range(N):
    for j in range(N):
        if i != j and graph[i][j] <= L:
            count[i][j] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            count[i][j] = min(count[i][j], count[i][k] + count[k][j])

for s, t in Y:
    if count[s - 1][t - 1] == INF:
        print(-1)
    else:
        print(count[s - 1][t - 1] - 1) N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L list(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split X = [list(map(int, input().split())) for _ in range(M)] X [list(map(int, input().split())) for _ in range(M)] Q = int(input()) Q int(input()) int input() input list(map(int, input().split())) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split Y = [list(map(int, input().split())) for _ in range(Q)] Y [list(map(int, input().split())) for _ in range(Q)] INF = 10 ** 9 + 7 INF 10 ** 9 + 7 10 ** 9 10 9 7 [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N graph = [[INF] * N for _ in range(N)] graph [[INF] * N for _ in range(N)] [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N count = [[INF] * N for _ in range(N)] count [[INF] * N for _ in range(N)] for i in range(N):
    graph[i][i] = 0
    count[i][i] = 0 i range(N) range N graph[i][i] = 0 graph[i][i] [i] graph i i 0 count[i][i] = 0 count[i][i] [i] count i i 0 for a, b, c in X:
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c a b c X graph[a - 1][b - 1] = c graph[a - 1][b - 1] [a - 1] graph a - 1 a 1 b - 1 b 1 c graph[b - 1][a - 1] = c graph[b - 1][a - 1] [b - 1] graph b - 1 b 1 a - 1 a 1 c for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]) i range(N) range N for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]) j range(N) range N graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]) graph[i][j] [i] graph i j min(graph[i][j], graph[i][k] + graph[k][j]) min graph[i][j] [i] graph i j graph[i][k] + graph[k][j] graph[i][k] [i] graph i k graph[k][j] [k] graph k j for i in range(N):
    for j in range(N):
        if i != j and graph[i][j] <= L:
            count[i][j] = 1 i range(N) range N for j in range(N):
        if i != j and graph[i][j] <= L:
            count[i][j] = 1 j range(N) range N if i != j and graph[i][j] <= L:
            count[i][j] = 1 i != j and graph[i][j] <= L i != j i j graph[i][j] <= L graph[i][j] [i] graph i j L count[i][j] = 1 count[i][j] [i] count i j 1 for k in range(N):
    for i in range(N):
        for j in range(N):
            count[i][j] = min(count[i][j], count[i][k] + count[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            count[i][j] = min(count[i][j], count[i][k] + count[k][j]) i range(N) range N for j in range(N):
            count[i][j] = min(count[i][j], count[i][k] + count[k][j]) j range(N) range N count[i][j] = min(count[i][j], count[i][k] + count[k][j]) count[i][j] [i] count i j min(count[i][j], count[i][k] + count[k][j]) min count[i][j] [i] count i j count[i][k] + count[k][j] count[i][k] [i] count i k count[k][j] [k] count k j for s, t in Y:
    if count[s - 1][t - 1] == INF:
        print(-1)
    else:
        print(count[s - 1][t - 1] - 1) s t Y if count[s - 1][t - 1] == INF:
        print(-1)
    else:
        print(count[s - 1][t - 1] - 1) count[s - 1][t - 1] == INF count[s - 1][t - 1] [s - 1] count s - 1 s 1 t - 1 t 1 INF print(-1) print -1 print(count[s - 1][t - 1] - 1) print count[s - 1][t - 1] - 1 count[s - 1][t - 1] [s - 1] count s - 1 s 1 t - 1 t 1 1 M, L = map(int, input().split()) map(int, input().split()) M INF = 10 ** 9 + 7 10 ** 9 + 7 INF N, M, L = map(int, input().split()) map(int, input().split()) N Y = [list(map(int, input().split())) for _ in range(Q)] [list(map(int, input().split())) for _ in range(Q)] Y X = [list(map(int, input().split())) for _ in range(M)] [list(map(int, input().split())) for _ in range(M)] X graph = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] graph count = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] count L = map(int, input().split()) map(int, input().split()) L Q = int(input()) int(input()) Q

N, M, L = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]
Q = int(input())
Y = [list(map(int, input().split())) for _ in range(Q)]

INF = 10 ** 9 + 7
graph = [[INF] * N for _ in range(N)]
count = [[INF] * N for _ in range(N)]
for i in range(N):
    graph[i][i] = 0
    count[i][i] = 0

for a, b, c in X:
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

for i in range(N):
    for j in range(N):
        if i != j and graph[i][j] <= L:
            count[i][j] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            count[i][j] = min(count[i][j], count[i][k] + count[k][j])

for s, t in Y:
    if count[s - 1][t - 1] == INF:
        print(-1)
    else:
        print(count[s - 1][t - 1] - 1)
