#include <bits/stdc++.h>
using namespace std;
#ifdef local
#include <debug.hpp>
#else
#define debug(...)
#endif
#define rep(i, n) for (int i = 0; i < n; i++)
template <class T> istream& operator>>(istream& I, vector<T>& V) {for (T& X : V) I >> X; return I;}
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
vector<int> di = {-1, 1, 0, 0}, dj = {0, 0, -1, 1}; int inf = 2e9; long INF = 1e18;

int main() {
    long y;
    int n, m, p;
    cin >> n >> m >> p >> y;
    vector<vector<pair<int, int>>> g(n);
    rep(i, m) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }

    vector<long> dist(n, INF);
    priority_queue<pair<long, int>, vector<pair<long, int>>, greater<pair<long, int>>> q;
    dist[0] = 0;
    q.emplace(0, 0);
    while (q.size()) {
        auto [d, v] = q.top(); q.pop();
        for (auto [u, w] : g[v]) {
            if (chmin(dist[u], d + w)) {
                q.emplace(dist[u], u);
            }
        }
    }

    long ans = 0;
    rep(i, p) {
        int d, e;
        cin >> d >> e;
        d--;
        long x = y - dist[d];
        chmax(ans, x / e);
    }
    cout << ans << endl;
    return 0;
}