#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

typedef pair<ll,pair<int,int>> pli;

int main(){
  int n,m,s;
  cin >> n >> m >> s;
  struct info{
    int to; int cost; int time;
  };
  
  vector<int> c(n),d(n);
  vector<info> v[n];
  rep(i,m){
    int a,b,p,q;
    cin >> p >> q >> a >> b;
    p--; q--;
    v[p].push_back({q,a,b});
    v[q].push_back({p,a,b});
  }
  rep(i,n){
    cin >> c[i] >> d[i];
  }

  vector<vector<ll>> dist(n, vector<ll>(2510,longinf)); //city silvercoin
  priority_queue<pli,vector<pli>,greater<pli>> q;
  dist[0][min(2500,s)]=0;
  q.push({0LL,{0,min(2500,s)}});  //dist city money

  while(q.size()){
    pli p=q.top(); q.pop();
    int now = p.S.F;
    int left = p.S.S;
    if(dist[now][left]!=p.F) continue;
    auto go = [&](int nxt, int nleft, int cost){
      if(dist[nxt][nleft]>p.F+cost) q.push({dist[nxt][nleft]=p.F+cost,{nxt,nleft}});
    };
    go(now, min(2500,left+c[now]), d[now]);
    for(auto it:v[now]){
      if(it.cost > left) continue;
      go(it.to, left-it.cost, it.time);
    }
  }

  REP(i,1,n){
    ll ans = longinf;
    rep(j,2501) ans = min(ans, dist[i][j]);
    cout << ans << endl;
  }
  return 0;
}