"""
気付き
１、float('inf')はちょい遅いみたい
２、input()よりもinput = sys.stdin.readlineの方が爆速らしい（知らんがな）
"""
import sys
inf = 10 ** 15
input = sys.stdin.readline

N, M, L = map(int, input().split())
dp = [[inf] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().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])
#print('distance={}'.format(dp))


dp2 = [[inf] * N for _ in range(N)]
for a in range(N - 1):
    for b in range(a+1, N):
        if dp[a][b] <= L:
            dp2[a][b] = 1
            dp2[b][a] = 1
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])
#print('times={}'.format(dp2))


Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    cost = dp2[s-1][t-1]
    if cost != inf:
        print(cost - 1)
    else:
        print(-1) """
気付き
１、float('inf')はちょい遅いみたい
２、input()よりもinput = sys.stdin.readlineの方が爆速らしい（知らんがな）
""" import sys sys inf = 10 ** 15 inf 10 ** 15 10 15 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input 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 _ in range(M):
    a, b, c = map(int, input().split())
    dp[a-1][b-1] = c
    dp[b-1][a-1] = 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 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])
#print('distance={}'.format(dp)) 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])
#print('distance={}'.format(dp)) i range(N) range N for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
#print('distance={}'.format(dp)) 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 a in range(N - 1):
    for b in range(a+1, N):
        if dp[a][b] <= L:
            dp2[a][b] = 1
            dp2[b][a] = 1 a range(N - 1) range N - 1 N 1 for b in range(a+1, N):
        if dp[a][b] <= L:
            dp2[a][b] = 1
            dp2[b][a] = 1 b range(a+1, N) range a+1 a 1 N if dp[a][b] <= L:
            dp2[a][b] = 1
            dp2[b][a] = 1 dp[a][b] <= L dp[a][b] [a] dp a b L dp2[a][b] = 1 dp2[a][b] [a] dp2 a b 1 dp2[b][a] = 1 dp2[b][a] [b] dp2 b a 1 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])
#print('times={}'.format(dp2)) 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])
#print('times={}'.format(dp2)) i range(N) range N for j in range(N):
            dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j])
#print('times={}'.format(dp2)) 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(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    cost = dp2[s-1][t-1]
    if cost != inf:
        print(cost - 1)
    else:
        print(-1) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t cost = dp2[s-1][t-1] cost dp2[s-1][t-1] [s-1] dp2 s-1 s 1 t-1 t 1 if cost != inf:
        print(cost - 1)
    else:
        print(-1) cost != inf cost inf print(cost - 1) print cost - 1 cost 1 print(-1) print -1 M, L = map(int, input().split()) map(int, input().split()) M c = map(int, input().split()) map(int, input().split()) c N, M, L = map(int, input().split()) map(int, input().split()) N a, b, c = map(int, input().split()) map(int, input().split()) a b, c = map(int, input().split()) map(int, input().split()) b dp2 = [[inf] * N for _ in range(N)] [[inf] * N for _ in range(N)] dp2 t = map(int, input().split()) map(int, input().split()) t dp = [[inf] * N for _ in range(N)] [[inf] * N for _ in range(N)] dp inf = 10 ** 15 10 ** 15 inf input = sys.stdin.readline sys.stdin.readline input L = map(int, input().split()) map(int, input().split()) L s, t = map(int, input().split()) map(int, input().split()) s Q = int(input()) int(input()) Q cost = dp2[s-1][t-1] dp2[s-1][t-1] cost
"""
気付き
１、float('inf')はちょい遅いみたい
２、input()よりもinput = sys.stdin.readlineの方が爆速らしい（知らんがな）
"""
import sys
inf = 10 ** 15
input = sys.stdin.readline

N, M, L = map(int, input().split())
dp = [[inf] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().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])
#print('distance={}'.format(dp))


dp2 = [[inf] * N for _ in range(N)]
for a in range(N - 1):
    for b in range(a+1, N):
        if dp[a][b] <= L:
            dp2[a][b] = 1
            dp2[b][a] = 1
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])
#print('times={}'.format(dp2))


Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    cost = dp2[s-1][t-1]
    if cost != inf:
        print(cost - 1)
    else:
        print(-1)
