from collections import defaultdict, deque, Counter
# from functools import cache
# import copy
from itertools import combinations, permutations, product, accumulate, groupby, chain
# from more_itertools import distinct_permutations
from heapq import heapify, heappop, heappush, heappushpop
import math
import bisect
# from pprint import pprint
from random import randint, shuffle, randrange
# from sortedcontainers import SortedSet, SortedList, SortedDict
import sys
# sys.setrecursionlimit(2000000)
input = lambda: sys.stdin.readline().rstrip('\n')
inf = float('inf')
mod1 = 10**9+7
mod2 = 998244353
def ceil_div(x, y): return -(-x//y)

#################################################   

N, M, P, Y = map(int, input().split())
adj = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1; b -= 1
    adj[a].append((b, c))
    adj[b].append((a, c))

def dijkstra(s):
    dist = [inf]*N
    dist[s] = 0
    hq = [(0, s)]
    while hq:
        d, now = heappop(hq)
        if d > dist[now]: continue
        for next, cost in adj[now]:
            nd = d+cost
            if dist[next] <= nd: continue
            dist[next] = nd
            heappush(hq, (nd, next)) 
    return dist

dist = dijkstra(0)
ans = 0
for _ in range(P):
    d, e = map(int, input().split())
    d -= 1
    ans = max(ans, max(Y-dist[d], 0)//e)
print(ans)