import math

N, M, L = list(map(int, input().split()))
graph = [[math.inf]*N for _ in range(N)]

for i in range(M):
    a, b, c = list(map(int, input().split()))
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c

Q = int(input())
query = [(0, 0) for _ in range(Q)]

for i in range(Q):
    query[i] = tuple(map(int, input().split()))

# Warshall-Floyd
for i in range(N):
    for j in range(N):
        for k in range(N):
            graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k])

fuel_cost = [[math.inf]*N for _ in range(N)]

for i in range(N):
    for j in range(N):
        if graph[i][j] <= L:
            fuel_cost[i][j] = 1

# Warshall-Floyd
for i in range(N):
    for j in range(N):
        for k in range(N):
            fuel_cost[j][k] = min(fuel_cost[j][k], fuel_cost[j][i] + fuel_cost[i][k])

for i in range(Q):
    if fuel_cost[query[i][0] - 1][query[i][1] - 1] == math.inf:
        print(-1)
    else:
        print(fuel_cost[query[i][0] - 1][query[i][1] - 1] - 1) import math math 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 [math.inf]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [math.inf]*N [math.inf] math.inf math inf N graph = [[math.inf]*N for _ in range(N)] graph [[math.inf]*N for _ in range(N)] for i in range(M):
    a, b, c = list(map(int, input().split()))
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c i 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 graph[a - 1][b - 1] = c graph[a - 1][b - 1] [a - 1] graph a - 1 a 1 b - 1 b 1 c graph[b - 1][a - 1] = c graph[b - 1][a - 1] [b - 1] graph b - 1 b 1 a - 1 a 1 c Q = int(input()) Q int(input()) int input() input (0, 0) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) (0, 0) 0 0 query = [(0, 0) for _ in range(Q)] query [(0, 0) for _ in range(Q)] for i in range(Q):
    query[i] = tuple(map(int, input().split()))

# Warshall-Floyd i range(Q) range Q query[i] = tuple(map(int, input().split())) query[i] query i tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split for i in range(N):
    for j in range(N):
        for k in range(N):
            graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]) i range(N) range N for j in range(N):
        for k in range(N):
            graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]) j range(N) range N for k in range(N):
            graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]) k range(N) range N graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]) graph[j][k] [j] graph j k min(graph[j][k], graph[j][i] + graph[i][k]) min graph[j][k] [j] graph j k graph[j][i] + graph[i][k] graph[j][i] [j] graph j i graph[i][k] [i] graph i k [math.inf]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [math.inf]*N [math.inf] math.inf math inf N fuel_cost = [[math.inf]*N for _ in range(N)] fuel_cost [[math.inf]*N for _ in range(N)] for i in range(N):
    for j in range(N):
        if graph[i][j] <= L:
            fuel_cost[i][j] = 1

# Warshall-Floyd i range(N) range N for j in range(N):
        if graph[i][j] <= L:
            fuel_cost[i][j] = 1

# Warshall-Floyd j range(N) range N if graph[i][j] <= L:
            fuel_cost[i][j] = 1

# Warshall-Floyd graph[i][j] <= L graph[i][j] [i] graph i j L fuel_cost[i][j] = 1 fuel_cost[i][j] [i] fuel_cost i j 1 for i in range(N):
    for j in range(N):
        for k in range(N):
            fuel_cost[j][k] = min(fuel_cost[j][k], fuel_cost[j][i] + fuel_cost[i][k]) i range(N) range N for j in range(N):
        for k in range(N):
            fuel_cost[j][k] = min(fuel_cost[j][k], fuel_cost[j][i] + fuel_cost[i][k]) j range(N) range N for k in range(N):
            fuel_cost[j][k] = min(fuel_cost[j][k], fuel_cost[j][i] + fuel_cost[i][k]) k range(N) range N fuel_cost[j][k] = min(fuel_cost[j][k], fuel_cost[j][i] + fuel_cost[i][k]) fuel_cost[j][k] [j] fuel_cost j k min(fuel_cost[j][k], fuel_cost[j][i] + fuel_cost[i][k]) min fuel_cost[j][k] [j] fuel_cost j k fuel_cost[j][i] + fuel_cost[i][k] fuel_cost[j][i] [j] fuel_cost j i fuel_cost[i][k] [i] fuel_cost i k for i in range(Q):
    if fuel_cost[query[i][0] - 1][query[i][1] - 1] == math.inf:
        print(-1)
    else:
        print(fuel_cost[query[i][0] - 1][query[i][1] - 1] - 1) i range(Q) range Q if fuel_cost[query[i][0] - 1][query[i][1] - 1] == math.inf:
        print(-1)
    else:
        print(fuel_cost[query[i][0] - 1][query[i][1] - 1] - 1) fuel_cost[query[i][0] - 1][query[i][1] - 1] == math.inf fuel_cost[query[i][0] - 1][query[i][1] - 1] [query[i][0] - 1] fuel_cost query[i][0] - 1 query[i][0] [i] query i 0 1 query[i][1] - 1 query[i][1] [i] query i 1 1 math.inf math inf print(-1) print -1 print(fuel_cost[query[i][0] - 1][query[i][1] - 1] - 1) print fuel_cost[query[i][0] - 1][query[i][1] - 1] - 1 fuel_cost[query[i][0] - 1][query[i][1] - 1] [query[i][0] - 1] fuel_cost query[i][0] - 1 query[i][0] [i] query i 0 1 query[i][1] - 1 query[i][1] [i] query i 1 1 1 a, b, c = list(map(int, input().split())) list(map(int, input().split())) a b, c = list(map(int, input().split())) list(map(int, input().split())) b M, L = list(map(int, input().split())) list(map(int, input().split())) M N, M, L = list(map(int, input().split())) list(map(int, input().split())) N c = list(map(int, input().split())) list(map(int, input().split())) c graph = [[math.inf]*N for _ in range(N)] [[math.inf]*N for _ in range(N)] graph fuel_cost = [[math.inf]*N for _ in range(N)] [[math.inf]*N for _ in range(N)] fuel_cost query = [(0, 0) for _ in range(Q)] [(0, 0) for _ in range(Q)] query L = list(map(int, input().split())) list(map(int, input().split())) L Q = int(input()) int(input()) Q
import math

N, M, L = list(map(int, input().split()))
graph = [[math.inf]*N for _ in range(N)]

for i in range(M):
    a, b, c = list(map(int, input().split()))
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c

Q = int(input())
query = [(0, 0) for _ in range(Q)]

for i in range(Q):
    query[i] = tuple(map(int, input().split()))

# Warshall-Floyd
for i in range(N):
    for j in range(N):
        for k in range(N):
            graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k])

fuel_cost = [[math.inf]*N for _ in range(N)]

for i in range(N):
    for j in range(N):
        if graph[i][j] <= L:
            fuel_cost[i][j] = 1

# Warshall-Floyd
for i in range(N):
    for j in range(N):
        for k in range(N):
            fuel_cost[j][k] = min(fuel_cost[j][k], fuel_cost[j][i] + fuel_cost[i][k])

for i in range(Q):
    if fuel_cost[query[i][0] - 1][query[i][1] - 1] == math.inf:
        print(-1)
    else:
        print(fuel_cost[query[i][0] - 1][query[i][1] - 1] - 1)