from scipy.sparse import*

f=csgraph.floyd_warshall

I=9e9

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

d=eval('[I]*-~n,'*-~n)

for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=c

d=f(d,0)

d[d>l]=I

d[d<I]=1

d=f(d)

for i in zip(*[iter(t[m*3+1:])]*2):

	print(((I>d[i])*int(d[i])-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()



#after contest
from scipy.sparse import *

f = csgraph.floyd_warshall
I = 9e9
n, m, l, *t = list(map(int, open(0).read().split()))
d = eval("[I]*-~n," * -~n)
for a, b, c in zip(*[iter(t[: m * 3])] * 3):
    d[a][b] = c
d = f(d, 0)
d[d > l] = I
d[d < I] = 1
d = f(d)
for i in zip(*[iter(t[m * 3 + 1 :])] * 2):
    print(((I > d[i]) * int(d[i]) - 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()
# after contest

-from scipy.sparse import * +def main(): +    from scipy.sparse.csgraph import floyd_warshall +    import numpy as np -f = csgraph.floyd_warshall -I = 9e9 -n, m, l, *t = list(map(int, open(0).read().split())) -d = eval("[I]*-~n," * -~n) -for a, b, c in zip(*[iter(t[: m * 3])] * 3): -    d[a][b] = c -d = f(d, 0) -d[d > l] = I -d[d < I] = 1 -d = f(d) -for i in zip(*[iter(t[m * 3 + 1 :])] * 2): -    print(((I > d[i]) * int(d[i]) - 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() +# after contest