N, M, L = map(int, input().split())
INF = 10 ** 12

G = [[INF] * (N+1) for _ in range(N+1)]

for _ in range(M):
    a, b, c = map(int, input().split())
    G[a][b] = c
    G[b][a] = c


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

GL = [[INF] * (N+1) for _ in range(N+1)]
for i in range(1, N):
    for j in range(i+1, N+1):
        if G[i][j] <= L:
            GL[i][j] = 1
            GL[j][i] = 1

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

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    ans = GL[s][t]
    if ans == INF:
        print(-1)
    else:
        print(ans-1)

 N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L INF = 10 ** 12 INF 10 ** 12 10 12 [INF] * (N+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [INF] * (N+1) [INF] INF N+1 N 1 G = [[INF] * (N+1) for _ in range(N+1)] G [[INF] * (N+1) for _ in range(N+1)] for _ in range(M):
    a, b, c = map(int, input().split())
    G[a][b] = c
    G[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 G[a][b] = c G[a][b] [a] G a b c G[b][a] = c G[b][a] [b] G b a c for k in range(1, N+1):
    for i in range(1, N+1):
        for j in range(1, N+1):
            G[i][j] = min(G[i][j], G[i][k] + G[k][j]) k range(1, N+1) range 1 N+1 N 1 for i in range(1, N+1):
        for j in range(1, N+1):
            G[i][j] = min(G[i][j], G[i][k] + G[k][j]) i range(1, N+1) range 1 N+1 N 1 for j in range(1, N+1):
            G[i][j] = min(G[i][j], G[i][k] + G[k][j]) j range(1, N+1) range 1 N+1 N 1 G[i][j] = min(G[i][j], G[i][k] + G[k][j]) G[i][j] [i] G i j min(G[i][j], G[i][k] + G[k][j]) min G[i][j] [i] G i j G[i][k] + G[k][j] G[i][k] [i] G i k G[k][j] [k] G k j [INF] * (N+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [INF] * (N+1) [INF] INF N+1 N 1 GL = [[INF] * (N+1) for _ in range(N+1)] GL [[INF] * (N+1) for _ in range(N+1)] for i in range(1, N):
    for j in range(i+1, N+1):
        if G[i][j] <= L:
            GL[i][j] = 1
            GL[j][i] = 1 i range(1, N) range 1 N for j in range(i+1, N+1):
        if G[i][j] <= L:
            GL[i][j] = 1
            GL[j][i] = 1 j range(i+1, N+1) range i+1 i 1 N+1 N 1 if G[i][j] <= L:
            GL[i][j] = 1
            GL[j][i] = 1 G[i][j] <= L G[i][j] [i] G i j L GL[i][j] = 1 GL[i][j] [i] GL i j 1 GL[j][i] = 1 GL[j][i] [j] GL j i 1 for k in range(1, N+1):
    for i in range(1, N+1):
        for j in range(1, N+1):
            GL[i][j] = min(GL[i][j], GL[i][k] + GL[k][j]) k range(1, N+1) range 1 N+1 N 1 for i in range(1, N+1):
        for j in range(1, N+1):
            GL[i][j] = min(GL[i][j], GL[i][k] + GL[k][j]) i range(1, N+1) range 1 N+1 N 1 for j in range(1, N+1):
            GL[i][j] = min(GL[i][j], GL[i][k] + GL[k][j]) j range(1, N+1) range 1 N+1 N 1 GL[i][j] = min(GL[i][j], GL[i][k] + GL[k][j]) GL[i][j] [i] GL i j min(GL[i][j], GL[i][k] + GL[k][j]) min GL[i][j] [i] GL i j GL[i][k] + GL[k][j] GL[i][k] [i] GL i k GL[k][j] [k] GL k j Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    ans = GL[s][t]
    if ans == INF:
        print(-1)
    else:
        print(ans-1) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t ans = GL[s][t] ans GL[s][t] [s] GL s t if ans == INF:
        print(-1)
    else:
        print(ans-1) ans == INF ans INF print(-1) print -1 print(ans-1) print ans-1 ans 1 t = map(int, input().split()) map(int, input().split()) t M, L = map(int, input().split()) map(int, input().split()) M G = [[INF] * (N+1) for _ in range(N+1)] [[INF] * (N+1) for _ in range(N+1)] G b, c = map(int, input().split()) map(int, input().split()) b L = map(int, input().split()) map(int, input().split()) L c = map(int, input().split()) map(int, input().split()) c GL = [[INF] * (N+1) for _ in range(N+1)] [[INF] * (N+1) for _ in range(N+1)] GL ans = GL[s][t] GL[s][t] ans INF = 10 ** 12 10 ** 12 INF a, b, c = map(int, input().split()) map(int, input().split()) a Q = int(input()) int(input()) Q s, t = map(int, input().split()) map(int, input().split()) s N, M, L = map(int, input().split()) map(int, input().split()) N
N, M, L = map(int, input().split())
INF = 10 ** 12

G = [[INF] * (N+1) for _ in range(N+1)]

for _ in range(M):
    a, b, c = map(int, input().split())
    G[a][b] = c
    G[b][a] = c


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

GL = [[INF] * (N+1) for _ in range(N+1)]
for i in range(1, N):
    for j in range(i+1, N+1):
        if G[i][j] <= L:
            GL[i][j] = 1
            GL[j][i] = 1

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

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    ans = GL[s][t]
    if ans == INF:
        print(-1)
    else:
        print(ans-1)


