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,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() 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,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 import sys sys import numpy as np numpy from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall t=np.fromstring(sys.stdin.buffer.read(),'i',sep=' ') t np.fromstring(sys.stdin.buffer.read(),'i',sep=' ') np.fromstring np fromstring sys.stdin.buffer.read() sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read 'i' sep=' ' sep ' ' n,m,l=t[:3] n t[:3] t :3 3 m l t=t[3:] t t[3:] t 3: 3 m*=3 m 3 print('\n'.join(map(str,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)))) print '\n'.join(map(str,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))) '\n'.join '\n' join map(str,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)) map str 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) 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 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 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) [t[m+1::2],t[m+2::2]].clip [t[m+1::2],t[m+2::2]] (floyd_warshall(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0)<=l) floyd_warshall floyd_warshall(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0)<=l floyd_warshall(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0) floyd_warshall csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2) csr_matrix (t[2:m:3],(t[:m:3],t[1:m:3])) t[2:m:3] t 2:m:3 2 m 3 (t[:m:3],t[1:m:3]) t[:m:3] t :m:3 m 3 t[1:m:3] t 1:m:3 1 m 3 [n+1]*2 [n+1] n+1 n 1 2 0 l t[m+1::2] t m+1::2 m+1 m 1 2 clip 0 n n 1 main() main 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,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)))) 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,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
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,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()