from scipy.sparse import*

f=csgraph.floyd_warshall

t=list(map(int,open('/dev/fd/0').read().split()))

n,m,l=t[:3]

m=m*3+3

for i in f(f(csr_matrix((t[5:m:3],(t[3:m:3],t[4:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n)%n-1:print(i)
def main():

  import sys

  import numpy as np

  from scipy.sparse import csr_matrix

  from scipy.sparse.csgraph import floyd_warshall

  t=np.fromstring(sys.stdin.buffer.read(),'i',sep=' ')

  n,m,l=t[:3]

  t=t[3:]

  m*=3

  print(('\n'.join(map(str,list(map(int,floyd_warshall(floyd_warshall(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 *

f = csgraph.floyd_warshall
t = list(map(int, open("/dev/fd/0").read().split()))
n, m, l = t[:3]
m = m * 3 + 3
for i in (
    f(f(csr_matrix((t[5:m:3], (t[3:m:3], t[4:m:3])), [n + 1] * 2), 0) <= l)[
        t[m + 1 :: 2], t[m + 2 :: 2]
    ].clip(0, n)
    % n
    - 1
):
    print(i)

def main():
    import sys
    import numpy as np
    from scipy.sparse import csr_matrix
    from scipy.sparse.csgraph import floyd_warshall

    t = np.fromstring(sys.stdin.buffer.read(), "i", sep=" ")
    n, m, l = t[:3]
    t = t[3:]
    m *= 3
    print(
        (
            "\n".join(
                map(
                    str,
                    list(
                        map(
                            int,
                            floyd_warshall(
                                floyd_warshall(
                                    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(): +    import sys +    import numpy as np +    from scipy.sparse import csr_matrix +    from scipy.sparse.csgraph import floyd_warshall -f = csgraph.floyd_warshall -t = list(map(int, open("/dev/fd/0").read().split())) -n, m, l = t[:3] -m = m * 3 + 3 -for i in ( -    f(f(csr_matrix((t[5:m:3], (t[3:m:3], t[4:m:3])), [n + 1] * 2), 0) <= l)[ -        t[m + 1 :: 2], t[m + 2 :: 2] -    ].clip(0, n) -    % n -    - 1 -): -    print(i) +    t = np.fromstring(sys.stdin.buffer.read(), "i", sep=" ") +    n, m, l = t[:3] +    t = t[3:] +    m *= 3 +    print( +        ( +            "\n".join( +                map( +                    str, +                    list( +                        map( +                            int, +                            floyd_warshall( +                                floyd_warshall( +                                    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()