from scipy.sparse.csgraph import floyd_warshall

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

edges = [[0] * N for _ in range(N)]

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

Q = int(input())
queries = []

for _ in range(Q):
    queries.append(list(map(int,input().split())))

# use flord warshall to find min path between all towns
edges = floyd_warshall(edges)

# if the two towns can be travelled to on one tank, add to our fuel graph with distance 1
for i in range(N):
    for j in range(N):
        if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0

# use flord warshall to find min number of fuel tanks to travel between two towns
edges = floyd_warshall(edges)

for query in queries:
    s = query[0] - 1
    t = query[1] - 1
    num_tanks = edges[s][t] - 1
    if num_tanks != float('inf'):
        print(int(num_tanks))
    else:
        print("-1") from scipy.sparse.csgraph import floyd_warshall 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 [0] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [0] * N [0] 0 N edges = [[0] * N for _ in range(N)] edges [[0] * N for _ in range(N)] for _ in range(M):
    A,B,C = list(map(int, input().split()))
    edges[A-1][B-1] = C
    edges[B-1][A-1] = 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 edges[A-1][B-1] = C edges[A-1][B-1] [A-1] edges A-1 A 1 B-1 B 1 C edges[B-1][A-1] = C edges[B-1][A-1] [B-1] edges B-1 B 1 A-1 A 1 C Q = int(input()) Q int(input()) int input() input queries = [] queries [] for _ in range(Q):
    queries.append(list(map(int,input().split())))

# use flord warshall to find min path between all towns _ range(Q) range Q queries.append(list(map(int,input().split()))) queries.append queries append list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split edges = floyd_warshall(edges) edges floyd_warshall(edges) floyd_warshall edges for i in range(N):
    for j in range(N):
        if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0

# use flord warshall to find min number of fuel tanks to travel between two towns i range(N) range N for j in range(N):
        if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0

# use flord warshall to find min number of fuel tanks to travel between two towns j range(N) range N if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0

# use flord warshall to find min number of fuel tanks to travel between two towns edges[i][j] <= L edges[i][j] [i] edges i j L edges[i][j] = 1 edges[i][j] [i] edges i j 1 edges[i][j] = 0 edges[i][j] [i] edges i j 0 edges = floyd_warshall(edges) edges floyd_warshall(edges) floyd_warshall edges for query in queries:
    s = query[0] - 1
    t = query[1] - 1
    num_tanks = edges[s][t] - 1
    if num_tanks != float('inf'):
        print(int(num_tanks))
    else:
        print("-1") query queries s = query[0] - 1 s query[0] - 1 query[0] query 0 1 t = query[1] - 1 t query[1] - 1 query[1] query 1 1 num_tanks = edges[s][t] - 1 num_tanks edges[s][t] - 1 edges[s][t] [s] edges s t 1 if num_tanks != float('inf'):
        print(int(num_tanks))
    else:
        print("-1") num_tanks != float('inf') num_tanks float('inf') float 'inf' print(int(num_tanks)) print int(num_tanks) int num_tanks print("-1") print "-1" C = list(map(int, input().split())) list(map(int, input().split())) C s = query[0] - 1 query[0] - 1 s num_tanks = edges[s][t] - 1 edges[s][t] - 1 num_tanks A,B,C = list(map(int, input().split())) list(map(int, input().split())) A Q = int(input()) int(input()) Q N,M,L = list(map(int, input().split())) list(map(int, input().split())) N queries = [] [] queries t = query[1] - 1 query[1] - 1 t M,L = list(map(int, input().split())) list(map(int, input().split())) M L = list(map(int, input().split())) list(map(int, input().split())) L edges = [[0] * N for _ in range(N)] [[0] * N for _ in range(N)] edges B,C = list(map(int, input().split())) list(map(int, input().split())) B edges = floyd_warshall(edges) floyd_warshall(edges) edges edges = floyd_warshall(edges) floyd_warshall(edges) edges
from scipy.sparse.csgraph import floyd_warshall

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

edges = [[0] * N for _ in range(N)]

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

Q = int(input())
queries = []

for _ in range(Q):
    queries.append(list(map(int,input().split())))

# use flord warshall to find min path between all towns
edges = floyd_warshall(edges)

# if the two towns can be travelled to on one tank, add to our fuel graph with distance 1
for i in range(N):
    for j in range(N):
        if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0

# use flord warshall to find min number of fuel tanks to travel between two towns
edges = floyd_warshall(edges)

for query in queries:
    s = query[0] - 1
    t = query[1] - 1
    num_tanks = edges[s][t] - 1
    if num_tanks != float('inf'):
        print(int(num_tanks))
    else:
        print("-1")
