from scipy.sparse.csgraph import floyd_warshall as fw

N, M, L = map(int, input().split())

S = [[float("inf") for i in range(N)] for i in range(N)]

for i in range(M):
    a, b, c = map(int, input().split())
    S[a-1][b-1] = c
    S[b-1][a-1] = c

Sdist = fw(S)

Ssup_init = [[float("inf") for i in range(N)] for i in range(N)]

for i in range(N):
    for j in range(N):
        if Sdist[i][j]<=L:
            Ssup_init[i][j] = 1

Ssup = fw(Ssup_init)

Q = int(input())

for i in range(Q):
    s, t = map(int, input().split())
    if Ssup[s-1][t-1]==float("inf"):
        print(-1)
    else:
        print(int(Ssup[s-1][t-1]-1)) from scipy.sparse.csgraph import floyd_warshall as fw 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 i in range(N) for i in range(N) i range(N) range N for i in range(N) [float("inf") for i in range(N)] S = [[float("inf") for i in range(N)] for i in range(N)] S [[float("inf") for i in range(N)] for i in range(N)] for i in range(M):
    a, b, c = map(int, input().split())
    S[a-1][b-1] = c
    S[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 S[a-1][b-1] = c S[a-1][b-1] [a-1] S a-1 a 1 b-1 b 1 c S[b-1][a-1] = c S[b-1][a-1] [b-1] S b-1 b 1 a-1 a 1 c Sdist = fw(S) Sdist fw(S) fw S [float("inf") for i in range(N)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [float("inf") for i in range(N)] Ssup_init = [[float("inf") for i in range(N)] for i in range(N)] Ssup_init [[float("inf") for i in range(N)] for i in range(N)] for i in range(N):
    for j in range(N):
        if Sdist[i][j]<=L:
            Ssup_init[i][j] = 1 i range(N) range N for j in range(N):
        if Sdist[i][j]<=L:
            Ssup_init[i][j] = 1 j range(N) range N if Sdist[i][j]<=L:
            Ssup_init[i][j] = 1 Sdist[i][j]<=L Sdist[i][j] [i] Sdist i j L Ssup_init[i][j] = 1 Ssup_init[i][j] [i] Ssup_init i j 1 Ssup = fw(Ssup_init) Ssup fw(Ssup_init) fw Ssup_init Q = int(input()) Q int(input()) int input() input for i in range(Q):
    s, t = map(int, input().split())
    if Ssup[s-1][t-1]==float("inf"):
        print(-1)
    else:
        print(int(Ssup[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 Ssup[s-1][t-1]==float("inf"):
        print(-1)
    else:
        print(int(Ssup[s-1][t-1]-1)) Ssup[s-1][t-1]==float("inf") Ssup[s-1][t-1] [s-1] Ssup s-1 s 1 t-1 t 1 float("inf") float "inf" print(-1) print -1 print(int(Ssup[s-1][t-1]-1)) print int(Ssup[s-1][t-1]-1) int Ssup[s-1][t-1]-1 Ssup[s-1][t-1] [s-1] Ssup s-1 s 1 t-1 t 1 1 Sdist = fw(S) fw(S) Sdist Ssup_init = [[float("inf") for i in range(N)] for i in range(N)] [[float("inf") for i in range(N)] for i in range(N)] Ssup_init c = map(int, input().split()) map(int, input().split()) c b, c = map(int, input().split()) map(int, input().split()) b L = map(int, input().split()) map(int, input().split()) L a, b, c = map(int, input().split()) map(int, input().split()) a S = [[float("inf") for i in range(N)] for i in range(N)] [[float("inf") for i in range(N)] for i in range(N)] S Ssup = fw(Ssup_init) fw(Ssup_init) Ssup s, t = map(int, input().split()) map(int, input().split()) s N, M, L = map(int, input().split()) map(int, input().split()) N t = map(int, input().split()) map(int, input().split()) t Q = int(input()) int(input()) Q M, L = map(int, input().split()) map(int, input().split()) M
from scipy.sparse.csgraph import floyd_warshall as fw

N, M, L = map(int, input().split())

S = [[float("inf") for i in range(N)] for i in range(N)]

for i in range(M):
    a, b, c = map(int, input().split())
    S[a-1][b-1] = c
    S[b-1][a-1] = c

Sdist = fw(S)

Ssup_init = [[float("inf") for i in range(N)] for i in range(N)]

for i in range(N):
    for j in range(N):
        if Sdist[i][j]<=L:
            Ssup_init[i][j] = 1

Ssup = fw(Ssup_init)

Q = int(input())

for i in range(Q):
    s, t = map(int, input().split())
    if Ssup[s-1][t-1]==float("inf"):
        print(-1)
    else:
        print(int(Ssup[s-1][t-1]-1))