# import numpy as np
from scipy.sparse.csgraph import floyd_warshall
N, M, L = map(int, input().split())

INF = 10 ** 18
dist1 = [[INF] * N for _ in range(N)]
for i in range(N):
    dist1[i][i] = 0

for _ in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    dist1[A][B] = C
    dist1[B][A] = C

dist1 = floyd_warshall(dist1)

dist2 = [[INF] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if dist1[i][j] <= L:
            dist2[i][j] = 1

dist2 = floyd_warshall(dist2)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if dist2[s][t] >= INF:
        print (-1)
    else:
        print (int(dist2[s][t] - 1)) from scipy.sparse.csgraph import floyd_warshall N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L INF = 10 ** 18 INF 10 ** 18 10 18 [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N dist1 = [[INF] * N for _ in range(N)] dist1 [[INF] * N for _ in range(N)] for i in range(N):
    dist1[i][i] = 0 i range(N) range N dist1[i][i] = 0 dist1[i][i] [i] dist1 i i 0 for _ in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    dist1[A][B] = C
    dist1[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 A -= 1 A 1 B -= 1 B 1 dist1[A][B] = C dist1[A][B] [A] dist1 A B C dist1[B][A] = C dist1[B][A] [B] dist1 B A C dist1 = floyd_warshall(dist1) dist1 floyd_warshall(dist1) floyd_warshall dist1 [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N dist2 = [[INF] * N for _ in range(N)] dist2 [[INF] * N for _ in range(N)] for i in range(N):
    for j in range(N):
        if dist1[i][j] <= L:
            dist2[i][j] = 1 i range(N) range N for j in range(N):
        if dist1[i][j] <= L:
            dist2[i][j] = 1 j range(N) range N if dist1[i][j] <= L:
            dist2[i][j] = 1 dist1[i][j] <= L dist1[i][j] [i] dist1 i j L dist2[i][j] = 1 dist2[i][j] [i] dist2 i j 1 dist2 = floyd_warshall(dist2) dist2 floyd_warshall(dist2) floyd_warshall dist2 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if dist2[s][t] >= INF:
        print (-1)
    else:
        print (int(dist2[s][t] - 1)) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t s -= 1 s 1 t -= 1 t 1 if dist2[s][t] >= INF:
        print (-1)
    else:
        print (int(dist2[s][t] - 1)) dist2[s][t] >= INF dist2[s][t] [s] dist2 s t INF print (-1) print -1 print (int(dist2[s][t] - 1)) print int(dist2[s][t] - 1) int dist2[s][t] - 1 dist2[s][t] [s] dist2 s t 1 Q = int(input()) int(input()) Q dist2 = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] dist2 INF = 10 ** 18 10 ** 18 INF dist1 = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] dist1 dist2 = floyd_warshall(dist2) floyd_warshall(dist2) dist2 B -= 1 1 B A -= 1 1 A C = map(int, input().split()) map(int, input().split()) C s, t = map(int, input().split()) map(int, input().split()) s s -= 1 1 s N, M, L = map(int, input().split()) map(int, input().split()) N 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 t = map(int, input().split()) map(int, input().split()) t M, L = map(int, input().split()) map(int, input().split()) M dist1 = floyd_warshall(dist1) floyd_warshall(dist1) dist1 t -= 1 1 t
# import numpy as np
from scipy.sparse.csgraph import floyd_warshall
N, M, L = map(int, input().split())

INF = 10 ** 18
dist1 = [[INF] * N for _ in range(N)]
for i in range(N):
    dist1[i][i] = 0

for _ in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    dist1[A][B] = C
    dist1[B][A] = C

dist1 = floyd_warshall(dist1)

dist2 = [[INF] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if dist1[i][j] <= L:
            dist2[i][j] = 1

dist2 = floyd_warshall(dist2)

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