#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

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

template <typename T>
struct edge {
    int to; T cost1, cost2;
    edge(int to, T cost1, T cost2) : to(to), cost1(cost1), cost2(cost2) {}
};


template <class K, class V>
class RadixHeap {
    static constexpr int bit_length = sizeof(K)*8;
    K last;
    size_t sz, cnt;
    array<vector<pair<K, V>>, bit_length> v;
    static inline int bsr(int x){
        return x ? bit_length-__builtin_clz(x) : 0;
    }
    static inline int bsr(ll x){
        return x ? bit_length-__builtin_clzll(x) : 0;
    }

    void pull() {
        if(cnt < v[0].size()) return;;
        int i = 1;
        while(v[i].empty()) i++;
        last = min_element(v[i].begin(),v[i].end())->first;
        for (auto &&x : v[i]) v[bsr(x.first ^ last)].push_back(x);
        v[i].clear();
    }
public:
    RadixHeap() : last(0), sz(0), cnt(0) {}
    void emplace(K x, V val){
        sz++;
        v[bsr(x^last)].emplace_back(x, val);
    }

    pair<K, V> top() {
        pull();
        return v[0][cnt];
    }

    void pop() {
        pull();
        sz--;
        cnt++;
    }

    size_t size() const { return sz; }
    bool empty() const { return !sz; }
};

int main() {
    int n, m, s;
    cin >> n >> m >> s;
    auto dp = make_v(n, 2501, INF<ll>);
    vector<vector<edge<int>>> G(n);
    for (int i = 0; i < m; ++i) {
        int 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<int> cs(n), ds(n);
    for (int i = 0; i < n; ++i) {
        cin >> cs[i] >> ds[i];
    }
    dp[0][min(2500, s)] = 0;
    RadixHeap<ll, int> Q;
    Q.emplace(0, min(2500, s));
    int mask = (1 << 15)-1;
    while(!Q.empty()){
        int i; ll cost;
        tie(cost, i) = Q.top(); Q.pop();
        int j = i&mask; i = i >> 15;
        if(dp[i][j] < cost) continue;
        int j2 = min(2500, j+cs[i]);
        if(dp[i][j2] > dp[i][j]+ds[i]){
            dp[i][j2] = dp[i][j]+ds[i];
            Q.emplace(dp[i][j2], (i << 15) + j2);
        }
        for (auto &&e : G[i]) {
            if(j < e.cost1) continue;
            j2 = j - e.cost1;
            if(dp[e.to][j2] > dp[i][j]+e.cost2){
                dp[e.to][j2] = dp[i][j]+e.cost2;
                Q.emplace(dp[e.to][j2], (e.to << 15)+j2);
            }
        }
    }
    for (int i = 1; i < n; ++i) {
        cout << *min_element(dp[i].begin(),dp[i].end()) << "\n";
    }
    return 0;
}

Measured memory_bytes: 12764