import math
import sys
input = sys.stdin.readline

N, M, L = list(map(int, input().split()))

T = []
T1 = []
for _ in range(N):
    T.append([float("inf")] * N)
    T1.append([float("inf")] * N)
for n in range(N):
    T[n][n] = 0
    T1[n][n] = 0

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

for k in range(N):
    for i in range(N):
        for j in range(N):
            if T[i][j] > T[i][k] + T[k][j]:
                T[i][j] = T[i][k] + T[k][j]

for j in range(N):
    for i in range(N):
        if i == j:
            continue
        if T[j][i] <= L:
            T1[j][i] = 1
            T1[i][j] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            if T1[i][j] > T1[i][k] + T1[k][j]:
                T1[i][j] = T1[i][k] + T1[k][j]

Q = int(input())
for _ in range(Q):
    S, G = list(map(int, input().split()))
    if math.isinf(T1[S-1][G-1]):
        print(-1)
    else:
        print(T1[S-1][G-1]-1) import math math import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, M, L = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M L T = [] T [] T1 = [] T1 [] for _ in range(N):
    T.append([float("inf")] * N)
    T1.append([float("inf")] * N) _ range(N) range N T.append([float("inf")] * N) T.append T append [float("inf")] * N [float("inf")] float("inf") float "inf" N T1.append([float("inf")] * N) T1.append T1 append [float("inf")] * N [float("inf")] float("inf") float "inf" N for n in range(N):
    T[n][n] = 0
    T1[n][n] = 0 n range(N) range N T[n][n] = 0 T[n][n] [n] T n n 0 T1[n][n] = 0 T1[n][n] [n] T1 n n 0 for _ in range(M):
    A, B, C = list(map(int, input().split()))
    A -= 1
    B -= 1
    T[A][B] = C
    T[B][A] = C _ range(M) range M A, B, C = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split B C A -= 1 A 1 B -= 1 B 1 T[A][B] = C T[A][B] [A] T A B C T[B][A] = C T[B][A] [B] T B A C for k in range(N):
    for i in range(N):
        for j in range(N):
            if T[i][j] > T[i][k] + T[k][j]:
                T[i][j] = T[i][k] + T[k][j] k range(N) range N for i in range(N):
        for j in range(N):
            if T[i][j] > T[i][k] + T[k][j]:
                T[i][j] = T[i][k] + T[k][j] i range(N) range N for j in range(N):
            if T[i][j] > T[i][k] + T[k][j]:
                T[i][j] = T[i][k] + T[k][j] j range(N) range N if T[i][j] > T[i][k] + T[k][j]:
                T[i][j] = T[i][k] + T[k][j] T[i][j] > T[i][k] + T[k][j] T[i][j] [i] T i j T[i][k] + T[k][j] T[i][k] [i] T i k T[k][j] [k] T k j T[i][j] = T[i][k] + T[k][j] T[i][j] [i] T i j T[i][k] + T[k][j] T[i][k] [i] T i k T[k][j] [k] T k j for j in range(N):
    for i in range(N):
        if i == j:
            continue
        if T[j][i] <= L:
            T1[j][i] = 1
            T1[i][j] = 1 j range(N) range N for i in range(N):
        if i == j:
            continue
        if T[j][i] <= L:
            T1[j][i] = 1
            T1[i][j] = 1 i range(N) range N if i == j:
            continue
         i == j i j continue if T[j][i] <= L:
            T1[j][i] = 1
            T1[i][j] = 1 T[j][i] <= L T[j][i] [j] T j i L T1[j][i] = 1 T1[j][i] [j] T1 j i 1 T1[i][j] = 1 T1[i][j] [i] T1 i j 1 for k in range(N):
    for i in range(N):
        for j in range(N):
            if T1[i][j] > T1[i][k] + T1[k][j]:
                T1[i][j] = T1[i][k] + T1[k][j] k range(N) range N for i in range(N):
        for j in range(N):
            if T1[i][j] > T1[i][k] + T1[k][j]:
                T1[i][j] = T1[i][k] + T1[k][j] i range(N) range N for j in range(N):
            if T1[i][j] > T1[i][k] + T1[k][j]:
                T1[i][j] = T1[i][k] + T1[k][j] j range(N) range N if T1[i][j] > T1[i][k] + T1[k][j]:
                T1[i][j] = T1[i][k] + T1[k][j] T1[i][j] > T1[i][k] + T1[k][j] T1[i][j] [i] T1 i j T1[i][k] + T1[k][j] T1[i][k] [i] T1 i k T1[k][j] [k] T1 k j T1[i][j] = T1[i][k] + T1[k][j] T1[i][j] [i] T1 i j T1[i][k] + T1[k][j] T1[i][k] [i] T1 i k T1[k][j] [k] T1 k j Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    S, G = list(map(int, input().split()))
    if math.isinf(T1[S-1][G-1]):
        print(-1)
    else:
        print(T1[S-1][G-1]-1) _ range(Q) range Q S, G = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split G if math.isinf(T1[S-1][G-1]):
        print(-1)
    else:
        print(T1[S-1][G-1]-1) math.isinf(T1[S-1][G-1]) math.isinf math isinf T1[S-1][G-1] [S-1] T1 S-1 S 1 G-1 G 1 print(-1) print -1 print(T1[S-1][G-1]-1) print T1[S-1][G-1]-1 T1[S-1][G-1] [S-1] T1 S-1 S 1 G-1 G 1 1 B, C = list(map(int, input().split())) list(map(int, input().split())) B B -= 1 1 B T = [] [] T N, M, L = list(map(int, input().split())) list(map(int, input().split())) N A -= 1 1 A Q = int(input()) int(input()) Q input = sys.stdin.readline sys.stdin.readline input G = list(map(int, input().split())) list(map(int, input().split())) G C = list(map(int, input().split())) list(map(int, input().split())) C S, G = list(map(int, input().split())) list(map(int, input().split())) S T1 = [] [] T1 L = list(map(int, input().split())) list(map(int, input().split())) L A, B, C = list(map(int, input().split())) list(map(int, input().split())) A M, L = list(map(int, input().split())) list(map(int, input().split())) M
import math
import sys
input = sys.stdin.readline

N, M, L = list(map(int, input().split()))

T = []
T1 = []
for _ in range(N):
    T.append([float("inf")] * N)
    T1.append([float("inf")] * N)
for n in range(N):
    T[n][n] = 0
    T1[n][n] = 0

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

for k in range(N):
    for i in range(N):
        for j in range(N):
            if T[i][j] > T[i][k] + T[k][j]:
                T[i][j] = T[i][k] + T[k][j]

for j in range(N):
    for i in range(N):
        if i == j:
            continue
        if T[j][i] <= L:
            T1[j][i] = 1
            T1[i][j] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            if T1[i][j] > T1[i][k] + T1[k][j]:
                T1[i][j] = T1[i][k] + T1[k][j]

Q = int(input())
for _ in range(Q):
    S, G = list(map(int, input().split()))
    if math.isinf(T1[S-1][G-1]):
        print(-1)
    else:
        print(T1[S-1][G-1]-1)
