#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef tuple<Int, Int,Int> T;
typedef pair<Int, Int> p;
const Int INF = 1e18;

struct edge{Int to, t;};

Int N, M, S;

// 頂点vで銀貨c枚持っている状態を頂点 v*2501+c とする 
vector<vector<edge>> G(51*2501);
vector<Int> dist(51*2501, INF);

void dijkstra(int s){
    // first:最短距離 second:頂点番号
    priority_queue<p, vector<p>, greater<p>> q;
    dist[s] = 0;
    q.push(p(0, s));

    while (!q.empty()){
        int cur_d = q.top().first;
        int cur_v = q.top().second;
        q.pop();

        if (cur_d > dist[cur_v]) continue;

        for (int i = 0; i < G[cur_v].size(); i++){
            edge e = G[cur_v][i];
            if (dist[cur_v] + e.t < dist[e.to]){
                dist[e.to] = dist[cur_v] + e.t;
                q.push(p(dist[e.to], e.to));
            }
        }
    }
}


int main(){
    cin >> N >> M >> S;
    if(S > 2500) S = 2500;

    rep(i,M){
        int u, v; Int a, b;
        cin >> u >> v >> a >> b;
        u--; v--;

        for(int j=a; j<=2500; j++){
            G[u*2501+j].push_back(edge{v*2501+(j-a),b});
            G[v*2501+j].push_back(edge{u*2501+(j-a),b});
        }
    }

    
    rep(i,N){
        Int c, d; cin >> c >> d;
        for(int j=0; j+c<=2500; j++){
            G[i*2501+j].push_back(edge{i*2501+(j+c),d});
        }
    }

    vector<Int> ans(51, INF);

    dijkstra(S);

    rep1(i,N-1){
        Int ans = INF;
        rep(j,2501){
            ans = min(ans, dist[i*2501+j]);
        }
        cout << ans << endl;
    }
}