from scipy.sparse.csgraph import floyd_warshall

import numpy as np

n,m,l,*L=list(map(int,open(0).read().split()))

abc=L[:3*m];st=L[3*m+1:]

town=[[float("inf")]*n for _ in range(n)]

for a,b,c in zip(*[iter(abc)]*3):

	if c<=l:

		town[a-1][b-1]=c

fw=floyd_warshall(town,0)

ti=floyd_warshall(np.where(fw<=l,1,fw),0)

for s,t in zip(*[iter(st)]*2):

	if ti[s-1,t-1]==float("inf"):

		print((-1))

	else:

		print((int(ti[s-1,t-1]-1)))
def main():

	from scipy.sparse.csgraph import floyd_warshall

	import numpy as np

	n, m, l, *L = list(map(int, open(0).read().split()))

	abc = L[:3 * m];

	st = L[3 * m + 1:]

	r = [[float("inf")] * n for _ in range(n)]

	for a, b, c in zip(*[iter(abc)] * 3):

		if c <= l: r[a - 1][b - 1] = c

	fw = floyd_warshall(r, 0)

	ans = floyd_warshall(np.where(fw <= l, 1, fw), 0) - 1

	for s, t in zip(*[iter(st)] * 2):

		x = ans[s - 1, t - 1]

		if x == float("inf"):

			print((-1))

		else:

			print((int(x)))





if __name__ == "__main__":

	main()
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

n, m, l, *L = list(map(int, open(0).read().split()))
abc = L[: 3 * m]
st = L[3 * m + 1 :]
town = [[float("inf")] * n for _ in range(n)]
for a, b, c in zip(*[iter(abc)] * 3):
    if c <= l:
        town[a - 1][b - 1] = c
fw = floyd_warshall(town, 0)
ti = floyd_warshall(np.where(fw <= l, 1, fw), 0)
for s, t in zip(*[iter(st)] * 2):
    if ti[s - 1, t - 1] == float("inf"):
        print((-1))
    else:
        print((int(ti[s - 1, t - 1] - 1)))

def main():
    from scipy.sparse.csgraph import floyd_warshall
    import numpy as np

    n, m, l, *L = list(map(int, open(0).read().split()))
    abc = L[: 3 * m]
    st = L[3 * m + 1 :]
    r = [[float("inf")] * n for _ in range(n)]
    for a, b, c in zip(*[iter(abc)] * 3):
        if c <= l:
            r[a - 1][b - 1] = c
    fw = floyd_warshall(r, 0)
    ans = floyd_warshall(np.where(fw <= l, 1, fw), 0) - 1
    for s, t in zip(*[iter(st)] * 2):
        x = ans[s - 1, t - 1]
        if x == float("inf"):
            print((-1))
        else:
            print((int(x)))


if __name__ == "__main__":
    main()

-from scipy.sparse.csgraph import floyd_warshall -import numpy as np +def main(): +    from scipy.sparse.csgraph import floyd_warshall +    import numpy as np -n, m, l, *L = list(map(int, open(0).read().split())) -abc = L[: 3 * m] -st = L[3 * m + 1 :] -town = [[float("inf")] * n for _ in range(n)] -for a, b, c in zip(*[iter(abc)] * 3): -    if c <= l: -        town[a - 1][b - 1] = c -fw = floyd_warshall(town, 0) -ti = floyd_warshall(np.where(fw <= l, 1, fw), 0) -for s, t in zip(*[iter(st)] * 2): -    if ti[s - 1, t - 1] == float("inf"): -        print((-1)) -    else: -        print((int(ti[s - 1, t - 1] - 1))) +    n, m, l, *L = list(map(int, open(0).read().split())) +    abc = L[: 3 * m] +    st = L[3 * m + 1 :] +    r = [[float("inf")] * n for _ in range(n)] +    for a, b, c in zip(*[iter(abc)] * 3): +        if c <= l: +            r[a - 1][b - 1] = c +    fw = floyd_warshall(r, 0) +    ans = floyd_warshall(np.where(fw <= l, 1, fw), 0) - 1 +    for s, t in zip(*[iter(st)] * 2): +        x = ans[s - 1, t - 1] +        if x == float("inf"): +            print((-1)) +        else: +            print((int(x))) + + +if __name__ == "__main__": +    main()