import sys


INF = 1 << 32 - 1
S = sys.stdin.readlines()
N, M, L = map(int, S[0].split())

dp = [[INF] * N for _ in range(N)]

for i in range(1, M + 1):
    A, B, C = map(int, S[i].split())
    dp[A - 1][B - 1] = C
    dp[B - 1][A - 1] = C
for i in range(N):
    dp[i][i] = 0

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


dp2 = [[INF] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if dp[i][j] <= L:
            dp2[i][j] = 1
for i in range(N):
    dp2[i][i] = 0

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


Q = int(S[M + 1])
for i in range(M + 2, M + 2 + Q):
    s, t = map(int, S[i].split())
    refuel = dp2[s - 1][t - 1]
    if refuel >= 10 ** 3:
        print(-1)
    else:
        print(refuel - 1) import sys sys INF = 1 << 32 - 1 INF 1 << 32 - 1 1 32 - 1 32 1 S = sys.stdin.readlines() S sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines N, M, L = map(int, S[0].split()) N map(int, S[0].split()) map int S[0].split() [0].split [0] S 0 split M L [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N dp = [[INF] * N for _ in range(N)] dp [[INF] * N for _ in range(N)] for i in range(1, M + 1):
    A, B, C = map(int, S[i].split())
    dp[A - 1][B - 1] = C
    dp[B - 1][A - 1] = C i range(1, M + 1) range 1 M + 1 M 1 A, B, C = map(int, S[i].split()) A map(int, S[i].split()) map int S[i].split() [i].split [i] S i split B C dp[A - 1][B - 1] = C dp[A - 1][B - 1] [A - 1] dp A - 1 A 1 B - 1 B 1 C dp[B - 1][A - 1] = C dp[B - 1][A - 1] [B - 1] dp B - 1 B 1 A - 1 A 1 C for i in range(N):
    dp[i][i] = 0 i range(N) range N dp[i][i] = 0 dp[i][i] [i] dp i i 0 for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) i range(N) range N for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) j range(N) range N dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) dp[i][j] [i] dp i j min(dp[i][j], dp[i][k] + dp[k][j]) min dp[i][j] [i] dp i j dp[i][k] + dp[k][j] dp[i][k] [i] dp i k dp[k][j] [k] dp k j [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N dp2 = [[INF] * N for _ in range(N)] dp2 [[INF] * N for _ in range(N)] for i in range(N):
    for j in range(N):
        if dp[i][j] <= L:
            dp2[i][j] = 1 i range(N) range N for j in range(N):
        if dp[i][j] <= L:
            dp2[i][j] = 1 j range(N) range N if dp[i][j] <= L:
            dp2[i][j] = 1 dp[i][j] <= L dp[i][j] [i] dp i j L dp2[i][j] = 1 dp2[i][j] [i] dp2 i j 1 for i in range(N):
    dp2[i][i] = 0 i range(N) range N dp2[i][i] = 0 dp2[i][i] [i] dp2 i i 0 for k in range(N):
    for i in range(N):
        for j in range(N):
            dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]) i range(N) range N for j in range(N):
            dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]) j range(N) range N dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]) dp2[i][j] [i] dp2 i j min(dp2[i][j], dp2[i][k] + dp2[k][j]) min dp2[i][j] [i] dp2 i j dp2[i][k] + dp2[k][j] dp2[i][k] [i] dp2 i k dp2[k][j] [k] dp2 k j Q = int(S[M + 1]) Q int(S[M + 1]) int S[M + 1] S M + 1 M 1 for i in range(M + 2, M + 2 + Q):
    s, t = map(int, S[i].split())
    refuel = dp2[s - 1][t - 1]
    if refuel >= 10 ** 3:
        print(-1)
    else:
        print(refuel - 1) i range(M + 2, M + 2 + Q) range M + 2 M 2 M + 2 + Q M + 2 M 2 Q s, t = map(int, S[i].split()) s map(int, S[i].split()) map int S[i].split() [i].split [i] S i split t refuel = dp2[s - 1][t - 1] refuel dp2[s - 1][t - 1] [s - 1] dp2 s - 1 s 1 t - 1 t 1 if refuel >= 10 ** 3:
        print(-1)
    else:
        print(refuel - 1) refuel >= 10 ** 3 refuel 10 ** 3 10 3 print(-1) print -1 print(refuel - 1) print refuel - 1 refuel 1 C = map(int, S[i].split()) map(int, S[i].split()) C M, L = map(int, S[0].split()) map(int, S[0].split()) M refuel = dp2[s - 1][t - 1] dp2[s - 1][t - 1] refuel N, M, L = map(int, S[0].split()) map(int, S[0].split()) N B, C = map(int, S[i].split()) map(int, S[i].split()) B S = sys.stdin.readlines() sys.stdin.readlines() S A, B, C = map(int, S[i].split()) map(int, S[i].split()) A t = map(int, S[i].split()) map(int, S[i].split()) t dp2 = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] dp2 s, t = map(int, S[i].split()) map(int, S[i].split()) s INF = 1 << 32 - 1 1 << 32 - 1 INF L = map(int, S[0].split()) map(int, S[0].split()) L dp = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] dp Q = int(S[M + 1]) int(S[M + 1]) Q
import sys


INF = 1 << 32 - 1
S = sys.stdin.readlines()
N, M, L = map(int, S[0].split())

dp = [[INF] * N for _ in range(N)]

for i in range(1, M + 1):
    A, B, C = map(int, S[i].split())
    dp[A - 1][B - 1] = C
    dp[B - 1][A - 1] = C
for i in range(N):
    dp[i][i] = 0

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


dp2 = [[INF] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if dp[i][j] <= L:
            dp2[i][j] = 1
for i in range(N):
    dp2[i][i] = 0

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


Q = int(S[M + 1])
for i in range(M + 2, M + 2 + Q):
    s, t = map(int, S[i].split())
    refuel = dp2[s - 1][t - 1]
    if refuel >= 10 ** 3:
        print(-1)
    else:
        print(refuel - 1)
