import sys sys.setrecursionlimit(10**6) N,M,P,Y = map(int,input().split()) G = [set() for _ in range(N)] for _ in range(M): a,b,c = map(int,input().split()) a,b = a-1,b-1 G[a].add((b,c)) G[b].add((a,c)) D = dict() for _ in range(P): d,e = map(int,input().split()) D[d] = e def dfs(x,k,m): global Ans Ans = max(Ans,k//m) V[x] = True for g,c in G[x]: if not V[g]: e = 10**12 if g in D: e = D[g] dfs(g,k-c,min(m,e)) V[x] = False Ans = 0 V = [False for _ in range(N)] dfs(0,Y,10**18) print(Ans)