from subprocess import*

call(('python3','-c',"""

from scipy.sparse import*

s=csgraph.floyd_warshall

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

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

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

d=s(d)

d[d>l]=9e9

d[d<=l]=1

d=s(d)

d[d>9e9]=9e9

for s,t in zip(*[iter(t[m*3+1:])]*2):print(int(d[s,t]%9e9-1))

"""))
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]=d[b][a]=c

d=f(d)

d[d>l]=I

d[d<I]=1

d=f(d)

d[d>I]=I

for i in zip(*[iter(t[m*3+1:])]*2):print((int(d[i]%I-1)))
from subprocess import *

call(
    (
        "python3",
        "-c",
        """
from scipy.sparse import*
s=csgraph.floyd_warshall
n,m,l,*t=map(int,open(0).read().split())
d=eval('[9e9]*-~n,'*-~n)
for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=d[b][a]=c
d=s(d)
d[d>l]=9e9
d[d<=l]=1
d=s(d)
d[d>9e9]=9e9
for s,t in zip(*[iter(t[m*3+1:])]*2):print(int(d[s,t]%9e9-1))
""",
    )
)

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] = d[b][a] = c
d = f(d)
d[d > l] = I
d[d < I] = 1
d = f(d)
d[d > I] = I
for i in zip(*[iter(t[m * 3 + 1 :])] * 2):
    print((int(d[i] % I - 1)))

-from subprocess import * +from scipy.sparse import * -call( -    ( -        "python3", -        "-c", -        """ -from scipy.sparse import* -s=csgraph.floyd_warshall -n,m,l,*t=map(int,open(0).read().split()) -d=eval('[9e9]*-~n,'*-~n) -for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=d[b][a]=c -d=s(d) -d[d>l]=9e9 -d[d<=l]=1 -d=s(d) -d[d>9e9]=9e9 -for s,t in zip(*[iter(t[m*3+1:])]*2):print(int(d[s,t]%9e9-1)) -""", -    ) -) +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] = d[b][a] = c +d = f(d) +d[d > l] = I +d[d < I] = 1 +d = f(d) +d[d > I] = I +for i in zip(*[iter(t[m * 3 + 1 :])] * 2): +    print((int(d[i] % I - 1)))