from scipy.sparse import*

f=csgraph.floyd_warshall

def main():

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

  d=[[0]*(n+1)for _ in range(n+1)]

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

  d=f(f(d,0)<=l)-1

  d[d>n]=-1

  d=d.astype('i')

  print(('\n'.join(map(str,[d[i]for i in zip(*[iter(t[m*3+1:])]*2)]))))

main()
from scipy.sparse import*

f=csgraph.floyd_warshall

def main():

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

  d=[[0]*(n+1)for _ in range(n+1)]

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

  d=f(f(d,0)<=l)-1

  d[d>n]=-1

  d=d.astype('U')

  print(('\n'.join(d[i]for i in zip(*[iter(t[m*3+1:])]*2))))

main()
from scipy.sparse import *

f = csgraph.floyd_warshall


def main():
    n, m, l, *t = list(map(int, open(0).read().split()))
    d = [[0] * (n + 1) for _ in range(n + 1)]
    for a, b, c in zip(*[iter(t[: m * 3])] * 3):
        d[a][b] = c
    d = f(f(d, 0) <= l) - 1
    d[d > n] = -1
    d = d.astype("i")
    print(("\n".join(map(str, [d[i] for i in zip(*[iter(t[m * 3 + 1 :])] * 2)]))))


main()

from scipy.sparse import *

f = csgraph.floyd_warshall


def main():
    n, m, l, *t = list(map(int, open(0).read().split()))
    d = [[0] * (n + 1) for _ in range(n + 1)]
    for a, b, c in zip(*[iter(t[: m * 3])] * 3):
        d[a][b] = c
    d = f(f(d, 0) <= l) - 1
    d[d > n] = -1
    d = d.astype("U")
    print(("\n".join(d[i] for i in zip(*[iter(t[m * 3 + 1 :])] * 2))))


main()

-    d = d.astype("i") -    print(("\n".join(map(str, [d[i] for i in zip(*[iter(t[m * 3 + 1 :])] * 2)])))) +    d = d.astype("U") +    print(("\n".join(d[i] for i in zip(*[iter(t[m * 3 + 1 :])] * 2))))