from collections import defaultdict from heapq import heappop, heappush INF = 10**18 def dijkstra(start, graph): n = len(graph) dist = [INF] * n dist[start] = 0 checked = [False] * n pq = [(0, start)] while len(pq) > 0: now_d, now_v = heappop(pq) if checked[now_v]: continue checked[now_v] = True for next_v, cost in graph[now_v]: if checked[next_v]: continue next_d = now_d + cost if next_d >= dist[next_v]: continue dist[next_v] = min(next_d, dist[next_v]) heappush(pq, (next_d, next_v)) return dist N, M, P, Y = map(int, input().split()) graph = [[] for _ in range(N)] for _ in range(M): A, B, C = map(int, input().split()) graph[A - 1].append((B - 1, C)) graph[B - 1].append((A - 1, C)) shops = defaultdict(lambda: INF) for _ in range(P): D, E = map(int, input().split()) shops[D - 1] = min(shops[D - 1], E) dist = dijkstra(0, graph) ans = 0 for i in range(N): if shops[i] < INF: ans = max(ans, (Y - dist[i]) // shops[i]) print(ans)