#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
const int mod = 1000000007;
const int max_n = 200005;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,m,s;cin >> n >>m >>s;if(s>=5010)s=5009;
    vvpl g(n*5010);
    rep(i,m){
        ll u,v,a,b;cin >> u >> v >>a >>b;u--;v--;
        rep(j,5010){
            if(j-a>=0){
                g[u*5010+j].pb({v*5010+j-a,b});
                g[v*5010+j].pb({u*5010+j-a,b});
            }
        }
    }
    rep(i,n){
        ll c,d;cin >> c >>d;
        rep(j,5010){
            if(j+c<5010)g[i*5010+j].pb({i*5010+j+c,d});
        }
    }
    vl d(n*5010,INF/10);
    pqueue(pl) que;
    que.push({0,s});
    d[s]=0;
    //ll cnt=0;
    while(!que.empty()){
        pl p=que.top();
        que.pop();
        ll v=p.se;
        if(d[v]<p.fi)continue;
        rep(i,g[v].size()){
            pl ed=g[v][i];
            if(d[ed.fi]>d[v]+ed.se){
                d[ed.fi]=d[v]+ed.se;
                que.push({d[ed.fi],ed.fi});
            }
        }
        //if(cnt<10){
            //rep(i,10)cout << d[i] <<" "<<d[i+5010] <<" "<< d[i+10020]<<endl;
            //cout <<endl;
        //}
        //cnt++;
    }
    rep(i,n-1){
        ll ans=INF;
        rep(j,5010){
            chmin(ans,d[(i+1)*5010+j]);
        }
        cout <<ans <<endl;
    }
}