from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
edges = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    edges[a - 1][b - 1] = c
    edges[b - 1][a - 1] = c

Q = int(input())
st = []
for _ in range(Q):
    st.append([int(j) - 1 for j in input().split()])

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

edges = floyd_warshall(edges)

for i, j in st:
    if edges[i][j] == float("inf"):
        print(-1)
    else:
        print(int(edges[i][j]) - 1) 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 [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 = map(int, input().split())
    edges[a - 1][b - 1] = c
    edges[b - 1][a - 1] = 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 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 st = [] st [] for _ in range(Q):
    st.append([int(j) - 1 for j in input().split()]) _ range(Q) range Q int(j) - 1 for j in input().split() for j in input().split() j input().split() ().split () input split for j in input().split() int(j) - 1 int(j) int j 1 st.append([int(j) - 1 for j in input().split()]) st.append st append [int(j) - 1 for j in 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 i range(N) range N for j in range(N):
        if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0 j range(N) range N if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0 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 i, j in st:
    if edges[i][j] == float("inf"):
        print(-1)
    else:
        print(int(edges[i][j]) - 1) i j st if edges[i][j] == float("inf"):
        print(-1)
    else:
        print(int(edges[i][j]) - 1) edges[i][j] == float("inf") edges[i][j] [i] edges i j float("inf") float "inf" print(-1) print -1 print(int(edges[i][j]) - 1) print int(edges[i][j]) - 1 int(edges[i][j]) int edges[i][j] [i] edges i j 1 a, b, c = map(int, input().split()) map(int, input().split()) a edges = floyd_warshall(edges) floyd_warshall(edges) edges st = [] [] st edges = [[0] * N for _ in range(N)] [[0] * N for _ in range(N)] edges c = map(int, input().split()) map(int, input().split()) c L = map(int, input().split()) map(int, input().split()) L N, M, L = map(int, input().split()) map(int, input().split()) N M, L = map(int, input().split()) map(int, input().split()) M b, c = map(int, input().split()) map(int, input().split()) b Q = int(input()) int(input()) Q edges = floyd_warshall(edges) floyd_warshall(edges) edges
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
edges = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    edges[a - 1][b - 1] = c
    edges[b - 1][a - 1] = c

Q = int(input())
st = []
for _ in range(Q):
    st.append([int(j) - 1 for j in input().split()])

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

edges = floyd_warshall(edges)

for i, j in st:
    if edges[i][j] == float("inf"):
        print(-1)
    else:
        print(int(edges[i][j]) - 1)
