from scipy.sparse import*

def main():

  f=csgraph.floyd_warshall

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

  m*=3

  *_,=map(print,f(f(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n)%n-1)

main()

from scipy.sparse import*

def main():

  f=csgraph.floyd_warshall

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

  m*=3

  print(('\n'.join(map(str,list(map(int,f(f(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n)%n-1))))))

main()
from scipy.sparse import *


def main():
    f = csgraph.floyd_warshall
    n, m, l, *t = map(int, open(0).read().split())
    m *= 3
    (*_,) = map(
        print,
        f(f(csr_matrix((t[2:m:3], (t[:m:3], t[1:m:3])), [n + 1] * 2), 0) <= l)[
            t[m + 1 :: 2], t[m + 2 :: 2]
        ].clip(0, n)
        % n
        - 1,
    )


main()

from scipy.sparse import *


def main():
    f = csgraph.floyd_warshall
    n, m, l, *t = list(map(int, open(0).read().split()))
    m *= 3
    print(
        (
            "\n".join(
                map(
                    str,
                    list(
                        map(
                            int,
                            f(
                                f(
                                    csr_matrix(
                                        (t[2:m:3], (t[:m:3], t[1:m:3])), [n + 1] * 2
                                    ),
                                    0,
                                )
                                <= l
                            )[t[m + 1 :: 2], t[m + 2 :: 2]].clip(0, n)
                            % n
                            - 1,
                        )
                    ),
                )
            )
        )
    )


main()

-    n, m, l, *t = map(int, open(0).read().split()) +    n, m, l, *t = list(map(int, open(0).read().split())) -    (*_,) = map( -        print, -        f(f(csr_matrix((t[2:m:3], (t[:m:3], t[1:m:3])), [n + 1] * 2), 0) <= l)[ -            t[m + 1 :: 2], t[m + 2 :: 2] -        ].clip(0, n) -        % n -        - 1, +    print( +        ( +            "\n".join( +                map( +                    str, +                    list( +                        map( +                            int, +                            f( +                                f( +                                    csr_matrix( +                                        (t[2:m:3], (t[:m:3], t[1:m:3])), [n + 1] * 2 +                                    ), +                                    0, +                                ) +                                <= l +                            )[t[m + 1 :: 2], t[m + 2 :: 2]].clip(0, n) +                            % n +                            - 1, +                        ) +                    ), +                ) +            ) +        )