N,M,P,Y=map(int,input().split()) edge=[[] for _ in range(N)] for _ in range(M): a,b,c=map(int,input().split()) a-=1 b-=1 edge[a].append((b,c)) edge[b].append((a,c)) from heapq import * D=[10**18]*N D[0]=0 H=[(0,0)] while H: cd,cp=heappop(H) if D[cp]nd: D[np]=nd heappush(H,(nd,np)) ans=0 for _ in range(P): d,e=map(int,input().split()) d-=1 rest=Y-D[d] ans=max(ans,rest//e) print(ans)