import sys

from scipy.sparse.csgraph import floyd_warshall as f

def main():

  n,m,l,*t=list(map(int,sys.stdin.buffer.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('i2')

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

main()
def main():

  import sys

  from scipy.sparse.csgraph import floyd_warshall as f

  n,m,l,*t=list(map(int,sys.stdin.buffer.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

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

main()
import sys
from scipy.sparse.csgraph import floyd_warshall as f


def main():
    n, m, l, *t = list(map(int, sys.stdin.buffer.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("i2")
    print(
        (
            "\n".join(
                map(
                    str,
                    list(map(d.__getitem__, list(zip(*[iter(t[m * 3 + 1 :])] * 2)))),
                )
            )
        )
    )


main()

def main():
    import sys
    from scipy.sparse.csgraph import floyd_warshall as f

    n, m, l, *t = list(map(int, sys.stdin.buffer.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
    print(
        (
            "\n".join(
                map(
                    str,
                    list(
                        map(
                            int,
                            list(
                                map(
                                    d.__getitem__,
                                    list(zip(*[iter(t[m * 3 + 1 :])] * 2)),
                                )
                            ),
                        )
                    ),
                )
            )
        )
    )


main()

-import sys -from scipy.sparse.csgraph import floyd_warshall as f +def main(): +    import sys +    from scipy.sparse.csgraph import floyd_warshall as f - -def main(): -    d = d.astype("i2") -                    list(map(d.__getitem__, list(zip(*[iter(t[m * 3 + 1 :])] * 2)))), +                    list( +                        map( +                            int, +                            list( +                                map( +                                    d.__getitem__, +                                    list(zip(*[iter(t[m * 3 + 1 :])] * 2)), +                                ) +                            ), +                        ) +                    ),