#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

//有向、無向グラフ共通クラス(隣接リスト)
struct Graph {
    int n;
    using WEIGHT_TYPE = long long;
    const WEIGHT_TYPE INF = 1e18;
    struct Edge {
        int to;
        WEIGHT_TYPE weight;
        WEIGHT_TYPE weight_s;
    };
    struct Edge2 {
        int from;
        int to;
        WEIGHT_TYPE weight;
    };
    vector<vector<Edge>> es;
    Graph(int n) : n(n), es(n) {}

    // dijkstra O(E log V)
    vector<vector<WEIGHT_TYPE>> dijkstra(int s, const vi& C, const vi& D, int S) {
        const int MAX = 2505;
        vector<vector<WEIGHT_TYPE>> d(n, vector<WEIGHT_TYPE>(MAX+1, INF));
        d[s][min(S, MAX)] = 0;
        using P = pair<WEIGHT_TYPE, pii>;
        priority_queue<P, vector<P>, greater<P>> q;
        q.push({0LL, {s, min(S, MAX)}});
        while(!q.empty()) {
            auto p = q.top();
            q.pop();
            int cur_s = p.second.se;
            int cur_i = p.se.fi;
            auto cost = p.first;
            if(d[cur_i][cur_s] < p.first) continue;
            // cout << cur_s << " " << cur_i << " " << cost << '\n';
            for(auto &e : es[cur_i]) {
                int to = e.to;
                auto dist = e.weight + cost;
                auto nxt_s = cur_s-e.weight_s;
                if(nxt_s >= 0 && dist < d[to][nxt_s]) {
                    d[to][nxt_s] = dist;
                    q.push({dist, {to, nxt_s}});
                }
            }
            if(cur_s<MAX) {
                int nxt_s = min(cur_s+C[cur_i], MAX);
                if(d[cur_i][nxt_s] > cost + D[cur_i]) {
                    d[cur_i][nxt_s] = cost + D[cur_i];
                    q.push({d[cur_i][nxt_s], {cur_i, nxt_s}});
                }
            }
        }
        return d;
    }
    // dijkstra O(V^2)
    vector<WEIGHT_TYPE> dijkstra2(int s) {
        vector<WEIGHT_TYPE> d(n, INF);
        d[s] = 0;
        vector<int> used(n);
        auto mat = getEdgeMat();
        while(1) {
            int cur = -1;
            rep(i, n) {
                if(used[i]) continue;
                if(cur == -1 || d[i] < d[cur]) cur = i;
            }
            if(cur == -1) break;
            used[cur] = 1;
            rep(i, n) { chmin(d[i], d[cur] + mat[cur][i]); }
        }
        return d;
    }
    // warshall_floyd O(n^3)
    vector<vector<WEIGHT_TYPE>> warshall_floyd() {
        // vector<vector<WEIGHT_TYPE>> d(n, vector<WEIGHT_TYPE>(n, INF));
        // rep(i, n) d[i][i] = 0LL;
        // rep(i, n) for (auto && e : es[i]) {
        //     int j = e.to;
        //     chmin(d[i][j], e.weight);
        // }
        auto d = getEdgeMat();
        rep(k, n) rep(i, n) rep(j, n) { chmin(d[i][j], d[i][k] + d[k][j]); }
        return d;
    }
    // 頂点sから到達できるか
    vector<bool> getVisitable(int s) {
        vector<bool> ret(n);
        queue<int> q;
        q.push(s);
        ret[s] = true;
        while(!q.empty()) {
            auto cur = q.front();
            q.pop();
            for(auto &&e : es[cur]) {
                if(!ret[e.to]) {
                    ret[e.to] = true;
                    q.push(e.to);
                }
            }
        }
        return ret;
    }
    // 2部グラフ判定
    bool isBipartile() {
        vector<int> memo(n, -1);
        rep(i, n) {
            if(memo[i] != -1) continue;
            queue<int> q;
            q.push(i);
            memo[i] = 0;
            while(!q.empty()) {
                auto v = q.front();
                q.pop();
                for(auto &&e : es[v]) {
                    auto u = e.to;
                    if(memo[u] == -1) {
                        memo[u] = !memo[v];
                        q.push(u);
                    } else if(memo[u] == memo[v]) {
                        return false;
                    }
                }
            }
        }
        return true;
    }
    vector<vector<WEIGHT_TYPE>> getEdgeMat() {
        vector<vector<WEIGHT_TYPE>> mat(n, vector<WEIGHT_TYPE>(n, INF));
        rep(i, n) mat[i][i] = 0;
        rep(i, n) {
            for(auto &&e : es[i]) chmin(mat[i][e.to], e.weight);
        }
        return mat;
    }
};

// 無向グラフ
struct GraphUD : public Graph {
    GraphUD(int n) : Graph(n) {}
    void add_edge(int from, int to, WEIGHT_TYPE weight, WEIGHT_TYPE weight_s) {
        es[from].push_back({to, weight, weight_s});
        es[to].push_back({from, weight, weight_s});
    }
    vector<Edge2> getEdge2() {
        vector<Edge2> ret;
        rep(i, n) for(auto &&e : es[i]) {
            if(i < e.to) ret.push_back({i, e.to, e.weight});
        }
        return ret;
    }
    // 橋の検出
    // http://nupioca.hatenadiary.jp/entry/2013/11/03/200006
    // Calculate bridges in a undirected graph.
    // Assume graph is connected and has no parallel edges or self-loops.
    vector<Edge2> getBridges() {
        int V = n;
        // res: bridges
        vector<Edge2> res;
        // assume at least the first vertex exists
        vector<int> low(V, -1); // lowest reacheable index
        vector<int> pre(V, -1); // pre-order index
        int count = 0;          // pre-order index counter

        // v: current node
        // from: parent node
        function<int(int, int)> dfs = [&](int v, int from) {
            pre[v] = count++;
            low[v] = pre[v];
            for(auto &&e : es[v]) {
                int to = e.to;
                if(pre[to] == -1) {
                    // destination has not been visited
                    // visit destination and update low[v]
                    low[v] = min(low[v], dfs(to, v));
                    if(low[to] == pre[to]) {
                        // edge is not contained in a closed path -> bridge
                        res.push_back({v, to, e.weight});
                    }
                } else {
                    if(from == to) {
                        // ignore a path to parent
                        continue;
                    }
                    low[v] = min(low[v], low[to]);
                }
            }
            return low[v];
        };

        dfs(0, -1); // start dfs from vertex 0

        return res;
    }
};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, s;
    cin >> n >> m >> s;
    GraphUD g(n);
    rep(i, m) {
        int a, b, c, d;
        cin >> a>> b >> c >> d;
        --a;
        --b;
        g.add_edge(a, b, d, c);
    }
    vi c(n), d(n);
    rep(i, n) cin >> c[i] >> d[i];
    auto dd = g.dijkstra(0, c, d, s);
    REP(i, 1, n) {
        ll ans = INF;
        for(auto&& x : dd[i]) chmin(ans, x);
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 6296