from collections import * import heapq from itertools import * from functools import cache, partial from pprint import pprint import sys from typing import Any, Final try: from icecream import ic except ImportError: # Graceful fallback if IceCream isn't installed. ic = lambda *a: None if not a else (a[0] if len(a) == 1 else a) # noqa debug = partial(print, file=sys.stderr) dpprint = partial(pprint, stream=sys.stderr) sys.setrecursionlimit(10**6) MOD = 998244353 N, M, P, Y = map(int, input().split()) G = [[] for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) a, b = a - 1, b - 1 G[a].append((c, b)) G[b].append((c, a)) T = [-1] * N for _ in range(P): d, e = map(int, input().split()) T[d - 1] = e s = 0 dist = [float("inf")] * N dist[s] = 0 used = [False] * N used[s] = True queue = [] for e in G[s]: heapq.heappush(queue, e) while queue: v_cost, v = heapq.heappop(queue) if used[v]: continue dist[v] = v_cost used[v] = True for u_cost, u in G[v]: if not used[u]: heapq.heappush(queue, (v_cost + u_cost, u)) ans = 0 for i in range(N): if T[i] == -1: continue t = T[i] dist_ = dist[i] ans = max(ans, (Y - dist_) // t) print(ans)