from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

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

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

graph = csr_matrix((cost, (start, goal)), shape = (N, N))
can_reach_with_L = floyd_warshall(graph, directed = False)
can_reach_with_L[can_reach_with_L > L] = 0
ans = floyd_warshall(can_reach_with_L, directed = False, unweighted = True)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if ans[s][t] == float('inf'):
        print(-1)
    else:
        print(int(ans[s][t] + 0.5) - 1) from scipy.sparse import csr_matrix 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 start = [] start [] goal = [] goal [] cost = [] cost [] for _ in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    start.append(A)
    goal.append(B)
    cost.append(C)
    start.append(B)
    goal.append(A)
    cost.append(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 start.append(A) start.append start append A goal.append(B) goal.append goal append B cost.append(C) cost.append cost append C start.append(B) start.append start append B goal.append(A) goal.append goal append A cost.append(C) cost.append cost append C graph = csr_matrix((cost, (start, goal)), shape = (N, N)) graph csr_matrix((cost, (start, goal)), shape = (N, N)) csr_matrix (cost, (start, goal)) cost (start, goal) start goal shape = (N, N) shape (N, N) N N can_reach_with_L = floyd_warshall(graph, directed = False) can_reach_with_L floyd_warshall(graph, directed = False) floyd_warshall graph directed = False directed False can_reach_with_L[can_reach_with_L > L] = 0 can_reach_with_L[can_reach_with_L > L] can_reach_with_L can_reach_with_L > L can_reach_with_L L 0 ans = floyd_warshall(can_reach_with_L, directed = False, unweighted = True) ans floyd_warshall(can_reach_with_L, directed = False, unweighted = True) floyd_warshall can_reach_with_L directed = False directed False unweighted = True unweighted True Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if ans[s][t] == float('inf'):
        print(-1)
    else:
        print(int(ans[s][t] + 0.5) - 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 ans[s][t] == float('inf'):
        print(-1)
    else:
        print(int(ans[s][t] + 0.5) - 1) ans[s][t] == float('inf') ans[s][t] [s] ans s t float('inf') float 'inf' print(-1) print -1 print(int(ans[s][t] + 0.5) - 1) print int(ans[s][t] + 0.5) - 1 int(ans[s][t] + 0.5) int ans[s][t] + 0.5 ans[s][t] [s] ans s t 0.5 1 goal = [] [] goal s -= 1 1 s cost = [] [] cost ans = floyd_warshall(can_reach_with_L, directed = False, unweighted = True) floyd_warshall(can_reach_with_L, directed = False, unweighted = True) ans t = map(int, input().split()) map(int, input().split()) t t -= 1 1 t B, C = map(int, input().split()) map(int, input().split()) B C = map(int, input().split()) map(int, input().split()) C M, L = map(int, input().split()) map(int, input().split()) M A, B, C = map(int, input().split()) map(int, input().split()) A s, t = map(int, input().split()) map(int, input().split()) s N, M, L = map(int, input().split()) map(int, input().split()) N A -= 1 1 A start = [] [] start graph = csr_matrix((cost, (start, goal)), shape = (N, N)) csr_matrix((cost, (start, goal)), shape = (N, N)) graph L = map(int, input().split()) map(int, input().split()) L Q = int(input()) int(input()) Q can_reach_with_L = floyd_warshall(graph, directed = False) floyd_warshall(graph, directed = False) can_reach_with_L B -= 1 1 B
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

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

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

graph = csr_matrix((cost, (start, goal)), shape = (N, N))
can_reach_with_L = floyd_warshall(graph, directed = False)
can_reach_with_L[can_reach_with_L > L] = 0
ans = floyd_warshall(can_reach_with_L, directed = False, unweighted = True)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if ans[s][t] == float('inf'):
        print(-1)
    else:
        print(int(ans[s][t] + 0.5) - 1)
