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

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

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

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

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 (dist2[s][t] - 1) 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 for k in range(N):
    for i in range(N):
        for j in range(N):
            dist1[i][j] = min(dist1[i][j], dist1[i][k] + dist1[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            dist1[i][j] = min(dist1[i][j], dist1[i][k] + dist1[k][j]) i range(N) range N for j in range(N):
            dist1[i][j] = min(dist1[i][j], dist1[i][k] + dist1[k][j]) j range(N) range N dist1[i][j] = min(dist1[i][j], dist1[i][k] + dist1[k][j]) dist1[i][j] [i] dist1 i j min(dist1[i][j], dist1[i][k] + dist1[k][j]) min dist1[i][j] [i] dist1 i j dist1[i][k] + dist1[k][j] dist1[i][k] [i] dist1 i k dist1[k][j] [k] dist1 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 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 for k in range(N):
    for i in range(N):
        for j in range(N):
            dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]) i range(N) range N for j in range(N):
            dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]) j range(N) range N dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]) dist2[i][j] [i] dist2 i j min(dist2[i][j], dist2[i][k] + dist2[k][j]) min dist2[i][j] [i] dist2 i j dist2[i][k] + dist2[k][j] dist2[i][k] [i] dist2 i k dist2[k][j] [k] dist2 k j 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 (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 (dist2[s][t] - 1) dist2[s][t] >= INF dist2[s][t] [s] dist2 s t INF print (-1) print -1 print (dist2[s][t] - 1) print dist2[s][t] - 1 dist2[s][t] [s] dist2 s t 1 Q = int(input()) int(input()) Q M, L = map(int, input().split()) map(int, input().split()) M s -= 1 1 s N, M, L = map(int, input().split()) map(int, input().split()) N B -= 1 1 B t = map(int, input().split()) map(int, input().split()) t s, t = map(int, input().split()) map(int, input().split()) s L = map(int, input().split()) map(int, input().split()) L INF = 10 ** 18 10 ** 18 INF dist1 = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] dist1 A, B, C = map(int, input().split()) map(int, input().split()) A B, C = map(int, input().split()) map(int, input().split()) B t -= 1 1 t C = map(int, input().split()) map(int, input().split()) C A -= 1 1 A dist2 = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] dist2
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

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

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

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

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 (dist2[s][t] - 1)