#include <bits/stdc++.h>
using namespace std;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define INF 1125899906842624
constexpr i64 MAX_S = 2500;
struct Edge {
    i64 to, fee, cost;
    Edge() {}
    Edge(i64 to, i64 fee, i64 cost) : to(to), fee(fee), cost(cost) {}
};
struct State {
    i64 v, s;
    State() {}
    State(i64 v, i64 s) : v(v), s(s) {}
};
vector<Edge> G[50];
i64 dp[50][MAX_S + 1];

int main() {
    i64 N, M, S; cin >> N >> M >> S;
    chmin(S, MAX_S);
    REP(i, M) {
        i64 u, v, a, b; cin >> u >> v >> a >> b;
        u--, v--;
        G[u].emplace_back(v, a, b);
        G[v].emplace_back(u, a, b);
    }
    vector<i64> C(N);
    vector<i64> D(N);
    REP(i, N) cin >> C[i] >> D[i];

    using P = pair<i64, State>;
    REP(i, N) REP(j, MAX_S + 1) dp[i][j] = INF;
    dp[0][S] = 0;
    auto comp = [&](const P &p1, const P &p2) { return p1.first > p2.first; };
    priority_queue<P, vector<P>, decltype(comp)> pq(comp);
    pq.push(P(0, State(0, S)));
    while(!pq.empty()) {
        P p = pq.top(); pq.pop();
        i64 time = p.first;
        const State &state = p.second;
        if (dp[state.v][state.s] < time) continue;

        i64 nt = time + D[state.v];
        i64 ns = min(MAX_S, state.s + C[state.v]);
        if (chmin(dp[state.v][ns], nt)) {
            pq.push(P(nt, State(state.v, ns)));
        }

        for (auto &e : G[state.v]) {
            if (state.s < e.fee) continue;
            i64 nt = time + e.cost;
            i64 ns = state.s - e.fee;
            if (chmin(dp[e.to][ns], nt)) {
                pq.push(P(nt, State(e.to, ns)));
            }
        }
    }

    REP(i, N) {
        if (i == 0) continue;
        i64 mint = INF;
        REP(j, MAX_S + 1) chmin(mint, dp[i][j]);
        cout << mint << endl;
    }

    return 0;
}

Measured memory_bytes: 7232