import sys
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix

input = sys.stdin.readline

n, m, l = list(map(int, input().split()))
g_dense = np.zeros((n, n))

for _ in range(m):
    a, b, c = map(int, input().split())
    g_dense[a-1][b-1] = c

q = int(input())
st = [list(map(int, input().split())) for _ in range(q)]

path = shortest_path(g_dense, directed=False)

g_dense = np.zeros((n, n))

for i in range(n):
    for j in range(n):
        if path[i][j] <= l:
            g_dense[i][j] = 1

path = shortest_path(g_dense, directed=False)

INF = float('inf')

for s,t in st:
    ans = path[s-1][t-1]
    if ans == INF:
        print(-1)
    else:
        print(int(ans) - 1) import sys sys import numpy as np numpy from scipy.sparse.csgraph import shortest_path from scipy.sparse import csr_matrix 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 g_dense = np.zeros((n, n)) g_dense np.zeros((n, n)) np.zeros np zeros (n, n) n n for _ in range(m):
    a, b, c = map(int, input().split())
    g_dense[a-1][b-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 g_dense[a-1][b-1] = c g_dense[a-1][b-1] [a-1] g_dense a-1 a 1 b-1 b 1 c q = int(input()) q int(input()) int input() input list(map(int, input().split())) for _ in range(q) for _ in range(q) _ range(q) range q for _ in range(q) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split st = [list(map(int, input().split())) for _ in range(q)] st [list(map(int, input().split())) for _ in range(q)] path = shortest_path(g_dense, directed=False) path shortest_path(g_dense, directed=False) shortest_path g_dense directed=False directed False g_dense = np.zeros((n, n)) g_dense np.zeros((n, n)) np.zeros np zeros (n, n) n n for i in range(n):
    for j in range(n):
        if path[i][j] <= l:
            g_dense[i][j] = 1 i range(n) range n for j in range(n):
        if path[i][j] <= l:
            g_dense[i][j] = 1 j range(n) range n if path[i][j] <= l:
            g_dense[i][j] = 1 path[i][j] <= l path[i][j] [i] path i j l g_dense[i][j] = 1 g_dense[i][j] [i] g_dense i j 1 path = shortest_path(g_dense, directed=False) path shortest_path(g_dense, directed=False) shortest_path g_dense directed=False directed False INF = float('inf') INF float('inf') float 'inf' for s,t in st:
    ans = path[s-1][t-1]
    if ans == INF:
        print(-1)
    else:
        print(int(ans) - 1) s t st ans = path[s-1][t-1] ans path[s-1][t-1] [s-1] path s-1 s 1 t-1 t 1 if ans == INF:
        print(-1)
    else:
        print(int(ans) - 1) ans == INF ans INF print(-1) print -1 print(int(ans) - 1) print int(ans) - 1 int(ans) int ans 1 g_dense = np.zeros((n, n)) np.zeros((n, n)) g_dense INF = float('inf') float('inf') INF n, m, l = list(map(int, input().split())) list(map(int, input().split())) n a, b, c = map(int, input().split()) map(int, input().split()) a c = map(int, input().split()) map(int, input().split()) c b, c = map(int, input().split()) map(int, input().split()) b input = sys.stdin.readline sys.stdin.readline input l = list(map(int, input().split())) list(map(int, input().split())) l g_dense = np.zeros((n, n)) np.zeros((n, n)) g_dense q = int(input()) int(input()) q m, l = list(map(int, input().split())) list(map(int, input().split())) m ans = path[s-1][t-1] path[s-1][t-1] ans path = shortest_path(g_dense, directed=False) shortest_path(g_dense, directed=False) path st = [list(map(int, input().split())) for _ in range(q)] [list(map(int, input().split())) for _ in range(q)] st path = shortest_path(g_dense, directed=False) shortest_path(g_dense, directed=False) path
import sys
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix

input = sys.stdin.readline

n, m, l = list(map(int, input().split()))
g_dense = np.zeros((n, n))

for _ in range(m):
    a, b, c = map(int, input().split())
    g_dense[a-1][b-1] = c

q = int(input())
st = [list(map(int, input().split())) for _ in range(q)]

path = shortest_path(g_dense, directed=False)

g_dense = np.zeros((n, n))

for i in range(n):
    for j in range(n):
        if path[i][j] <= l:
            g_dense[i][j] = 1

path = shortest_path(g_dense, directed=False)

INF = float('inf')

for s,t in st:
    ans = path[s-1][t-1]
    if ans == INF:
        print(-1)
    else:
        print(int(ans) - 1)