#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ppll = pair<ll, pll >;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N,M,S;

struct edge{
    ll to,cost,time;
    edge(ll to, ll c, ll t):to(to),cost(c),time(t){}
};

vector<vector<edge>> G;
ll A=0;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> N >> M >> S;
    G.resize(N);

    for (int i = 0; i < M; i++)
    {
        ll u,v;
        ll a,b;
        cin >> u >> v >> a >> b;
        u--,v--;
        G.at(u).emplace_back(v,a,b);
        G.at(v).emplace_back(u,a,b);
        A = max(A,a);
    }
    for (int i = 0; i < N; i++)
    {
        ll c,d; cin >> c >> d;
        G.at(i).emplace_back(i,-c,d);
    }
}

vector<ll> dijkstra(){
    priority_queue<ppll, vector<ppll>, greater<ppll> > pq;
    vector<vector<ll> > dist(N, vector<ll>(50*N+1, LL_INF));
    // vector<ll> dist(50*N*N+N+1, INT_INF);

    S = min(S, 50*N);
    for (int i = 0; i <= S; i++) dist.at(0).at(i) = 0LL;
    // for (int i = 0; i <= S; i++) dist.at(0+N*i) = 0;


    pq.emplace(0,make_pair(0,S));
    while(!pq.empty()){
        ll c_time;
        pll cur;
        tie(c_time, cur) = pq.top();
        ll idx = cur.first;
        ll coin = cur.second;
        pq.pop();
        
        if(dist.at(idx).at(coin) < c_time) continue;
        // if(dist.at(idx+N*coin) < c_time) continue;
        for(auto next:G.at(idx)){
            if(next.cost>coin) continue;
            ll ntime, nidx, ncoin;
            ntime = c_time + next.time;
            nidx = next.to;
            ncoin = coin - next.cost;
            ncoin = min(ncoin, 50*N);
            if(dist.at(nidx).at(ncoin) <= ntime) continue;
            // if(dist.at(nidx+N*ncoin) <= ntime) continue;
            dist.at(nidx).at(ncoin) = ntime;
            // dist.at(nidx+N*ncoin) = ntime;
            pq.emplace(ntime, make_pair(nidx,ncoin));
        }
    }
    vector<ll> ret(N,LL_INF);
    for (int i = 0; i < N; i++) ret.at(i) = *min_element(dist.at(i).begin(),dist.at(i).end());
    // for (int i = 0; i < N; i++) {
    //     for (int j = 0; j <= 50*N; j++)
    //     {
    //         ret.at(i) = min(ret.at(i), dist.at(i+N*j));
    //     }
        
    // }
    // DBG(dist)
    return ret;
}

int solve(){
    auto ans = dijkstra();
    for (int i = 1; i < N; i++) cout << ans.at(i) << "\n";

    return 0;    
}

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 7320