from heapq import heapify, heappop, heappush 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 -= 1 b -= 1 G[a].append((b, c)) G[b].append((a, c)) DE = [] for i in range(P): d, e = map(int, input().split()) d -= 1 DE.append((d, e)) def dijk(G, start=0): N = len(G) dist = [10**18]*N visited = [False]*N que = [] dist[start] = 0 heappush(que, (0, start)) while que: _, now = heappop(que) if visited[now] == True: continue visited[now] = True for to, weight in G[now]: if dist[now] + weight < dist[to]: dist[to] = dist[now] + weight heappush(que, (dist[now]+weight, to)) return dist stt = 0 dist = dijk(G, stt) # print(dist) ans = 0 for i in range(P): d, e = DE[i] x = (Y - dist[d]) // e ans = max(ans, x) print(ans)