#include <bits/stdc++.h> //#include <atcoder/modint> using namespace std; //using namespace atcoder; using ll = long long; //using mint = modint998244353; template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>; vector<ll> dijkstra(vector<vector<pair<ll, ll>>> &E, ll start){ ll N = E.size(); ll from, alt, d; pq<pair<ll, ll>> que; vector<ll> dist(N, 1e18); vector<bool> vst(N); dist[start] = 0; que.push({0, start}); while(!que.empty()){ tie(d, from) = que.top(); que.pop(); if (vst[from]) continue; vst[from] = 1; for (auto [to, C] : E[from]){ alt = d + C; if (alt < dist[to]){ dist[to] = alt; que.push({dist[to], to}); } } } return dist; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll N, M, P, Y, a, b, c, ans=0; cin >> N >> M >> P >> Y; vector<vector<pair<ll, ll>>> E(N); for (int i=0; i<M; i++){ cin >> a >> b >> c; a--; b--; E[a].push_back({b, c}); E[b].push_back({a, c}); } vector<ll> dist = dijkstra(E, 0); for (int i=0; i<P; i++){ cin >> a >> b; a--; if (Y<dist[a]) continue; ans = max(ans, (Y-dist[a])/b); } cout << ans << endl; return 0; }