#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll MAX = 2500LL;
typedef pair <ll, ll> P;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll n, m, s;
    cin >> n >> m >> s;
    s = min(s, MAX - 1);

    vector<vector<P>> edge(n * MAX);
    for (int i = 0; i < m; i++) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        for (int j = a; j < MAX; j++) {
            edge[u * MAX + j].push_back({v * MAX + j - a, b});
            edge[v * MAX + j].push_back({u * MAX + j - a, b});
        }
    }

    for (int i = 0; i < n; i++) {
        ll c, d;
        cin >> c >> d;
        for (int j = 0; j < MAX; j++) {
            edge[i * MAX + j].push_back({i * MAX + min(j + c, MAX - 1), d});
        }
    }

    vector <ll> ans(n * MAX, 1LL << 60);
    priority_queue <P, vector<P>, greater<P>> q;
    ans[s] = 0;
    q.push({0, s});

    while (!q.empty()) {
        P p = q.top();
        q.pop();
        ll time = p.first;
        int cur = p.second;
        if (ans[cur] < time) continue;
        for (P nxt : edge[cur]) {
            int next_node = nxt.first;
            ll total_time = time + nxt.second;
            if (ans[next_node] > total_time) {
                ans[next_node] = total_time;
                q.push({total_time, next_node});
            }
        }
    }

    for (int i = 1; i < n; i++) {
        ll mn = 1LL << 60;
        for (int j = 0; j < MAX; j++) mn = min(mn, ans[i * MAX + j]);
        cout << mn << '\n';
    }
    return 0;
}
