import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
    N,M,L=map(int,input().split())
    ABCQST=np.array(read().split(),np.int64)
    ABC=ABCQST[:3*M]
    A=ABC[::3]
    B=ABC[1::3]
    C=ABC[2::3]
    ST=ABCQST[3*M+1:]
    S=ST[::2]
    T=ST[1::2]

    graph1=csr_matrix((C,(A,B)),(N+1,N+1))
    graph1_dist=floyd_warshall(graph1,directed=False)

    graph2=np.full(((N+1),(N+1)),np.inf)
    np.fill_diagonal(graph2,0)
    graph2[graph1_dist<=L+0.5]=1

    graph2_dist=floyd_warshall(graph2,directed=False)
    graph2_dist[graph2_dist==np.inf]=0
    graph2_dist=(graph2_dist+0.5).astype(int)
    ans=graph2_dist[S,T]-1
    print("\n".join(ans.astype(str)))


if __name__ == '__main__':
    main() import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline inputs= sys.stdin.buffer.readlines inputs sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines import numpy as np numpy from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall def main():
    N,M,L=map(int,input().split())
    ABCQST=np.array(read().split(),np.int64)
    ABC=ABCQST[:3*M]
    A=ABC[::3]
    B=ABC[1::3]
    C=ABC[2::3]
    ST=ABCQST[3*M+1:]
    S=ST[::2]
    T=ST[1::2]

    graph1=csr_matrix((C,(A,B)),(N+1,N+1))
    graph1_dist=floyd_warshall(graph1,directed=False)

    graph2=np.full(((N+1),(N+1)),np.inf)
    np.fill_diagonal(graph2,0)
    graph2[graph1_dist<=L+0.5]=1

    graph2_dist=floyd_warshall(graph2,directed=False)
    graph2_dist[graph2_dist==np.inf]=0
    graph2_dist=(graph2_dist+0.5).astype(int)
    ans=graph2_dist[S,T]-1
    print("\n".join(ans.astype(str))) main N,M,L=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L ABCQST=np.array(read().split(),np.int64) ABCQST np.array(read().split(),np.int64) np.array np array read().split() ().split () read split np.int64 np int64 ABC=ABCQST[:3*M] ABC ABCQST[:3*M] ABCQST :3*M 3*M 3 M A=ABC[::3] A ABC[::3] ABC ::3 3 B=ABC[1::3] B ABC[1::3] ABC 1::3 1 3 C=ABC[2::3] C ABC[2::3] ABC 2::3 2 3 ST=ABCQST[3*M+1:] ST ABCQST[3*M+1:] ABCQST 3*M+1: 3*M+1 3*M 3 M 1 S=ST[::2] S ST[::2] ST ::2 2 T=ST[1::2] T ST[1::2] ST 1::2 1 2 graph1=csr_matrix((C,(A,B)),(N+1,N+1)) graph1 csr_matrix((C,(A,B)),(N+1,N+1)) csr_matrix (C,(A,B)) C (A,B) A B (N+1,N+1) N+1 N 1 N+1 N 1 graph1_dist=floyd_warshall(graph1,directed=False) graph1_dist floyd_warshall(graph1,directed=False) floyd_warshall graph1 directed=False directed False graph2=np.full(((N+1),(N+1)),np.inf) graph2 np.full(((N+1),(N+1)),np.inf) np.full np full ((N+1),(N+1)) N+1 N 1 N+1 N 1 np.inf np inf np.fill_diagonal(graph2,0) np.fill_diagonal np fill_diagonal graph2 0 graph2[graph1_dist<=L+0.5]=1 graph2[graph1_dist<=L+0.5] graph2 graph1_dist<=L+0.5 graph1_dist L+0.5 L 0.5 1 graph2_dist=floyd_warshall(graph2,directed=False) graph2_dist floyd_warshall(graph2,directed=False) floyd_warshall graph2 directed=False directed False graph2_dist[graph2_dist==np.inf]=0 graph2_dist[graph2_dist==np.inf] graph2_dist graph2_dist==np.inf graph2_dist np.inf np inf 0 graph2_dist=(graph2_dist+0.5).astype(int) graph2_dist (graph2_dist+0.5).astype(int) graph2_dist+0.5).astype graph2_dist+0.5 graph2_dist 0.5 astype int ans=graph2_dist[S,T]-1 ans graph2_dist[S,T]-1 graph2_dist[S,T] graph2_dist S 1 print("\n".join(ans.astype(str))) print "\n".join(ans.astype(str)) "\n".join "\n" join ans.astype(str) ans.astype ans astype str if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main input = sys.stdin.buffer.readline sys.stdin.buffer.readline input inputs= sys.stdin.buffer.readlines sys.stdin.buffer.readlines inputs def main():
    N,M,L=map(int,input().split())
    ABCQST=np.array(read().split(),np.int64)
    ABC=ABCQST[:3*M]
    A=ABC[::3]
    B=ABC[1::3]
    C=ABC[2::3]
    ST=ABCQST[3*M+1:]
    S=ST[::2]
    T=ST[1::2]

    graph1=csr_matrix((C,(A,B)),(N+1,N+1))
    graph1_dist=floyd_warshall(graph1,directed=False)

    graph2=np.full(((N+1),(N+1)),np.inf)
    np.fill_diagonal(graph2,0)
    graph2[graph1_dist<=L+0.5]=1

    graph2_dist=floyd_warshall(graph2,directed=False)
    graph2_dist[graph2_dist==np.inf]=0
    graph2_dist=(graph2_dist+0.5).astype(int)
    ans=graph2_dist[S,T]-1
    print("\n".join(ans.astype(str))) def main():
    N,M,L=map(int,input().split())
    ABCQST=np.array(read().split(),np.int64)
    ABC=ABCQST[:3*M]
    A=ABC[::3]
    B=ABC[1::3]
    C=ABC[2::3]
    ST=ABCQST[3*M+1:]
    S=ST[::2]
    T=ST[1::2]

    graph1=csr_matrix((C,(A,B)),(N+1,N+1))
    graph1_dist=floyd_warshall(graph1,directed=False)

    graph2=np.full(((N+1),(N+1)),np.inf)
    np.fill_diagonal(graph2,0)
    graph2[graph1_dist<=L+0.5]=1

    graph2_dist=floyd_warshall(graph2,directed=False)
    graph2_dist[graph2_dist==np.inf]=0
    graph2_dist=(graph2_dist+0.5).astype(int)
    ans=graph2_dist[S,T]-1
    print("\n".join(ans.astype(str))) main read = sys.stdin.buffer.read sys.stdin.buffer.read read
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
    N,M,L=map(int,input().split())
    ABCQST=np.array(read().split(),np.int64)
    ABC=ABCQST[:3*M]
    A=ABC[::3]
    B=ABC[1::3]
    C=ABC[2::3]
    ST=ABCQST[3*M+1:]
    S=ST[::2]
    T=ST[1::2]

    graph1=csr_matrix((C,(A,B)),(N+1,N+1))
    graph1_dist=floyd_warshall(graph1,directed=False)

    graph2=np.full(((N+1),(N+1)),np.inf)
    np.fill_diagonal(graph2,0)
    graph2[graph1_dist<=L+0.5]=1

    graph2_dist=floyd_warshall(graph2,directed=False)
    graph2_dist[graph2_dist==np.inf]=0
    graph2_dist=(graph2_dist+0.5).astype(int)
    ans=graph2_dist[S,T]-1
    print("\n".join(ans.astype(str)))


if __name__ == '__main__':
    main()