#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;
int maxs = 2500;

vector<ll> dijkstra(vector<vector<pair<int, ll>>> g, int s){
  int n = g.size();
  vector<ll> dist(n, INF);
  dist[s] = 0;
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
  pq.push({0, s});
  while(!pq.empty()){
    auto[d, v] = pq.top(); pq.pop();
    if(d > dist[v]) continue;
    for(auto e : g[v]){
      auto[nv, c] = e;
      if(dist[nv] > dist[v]+c){
        dist[nv] = dist[v]+c;
        pq.push({dist[nv], nv});
      }
    }
  }
  return dist;
}
int main(){
  int N, M, S;
  cin >> N >> M >> S;
  S = min(S, 2499);
  vector<vector<pair<int, ll>>> g(N*2500);
  REP(i, M){
    int U, V, A, B;
    cin >> U >> V >> A >> B;
    U--, V--;
    FOR(j, A, maxs){
      g[U*maxs+j].push_back({V*maxs+j-A, B});
      g[V*maxs+j].push_back({U*maxs+j-A, B});
    }
  }
  REP(i, N){
    int C, D;
    cin >> C >> D;
    REP(j, maxs-C){
      g[i*maxs+j].push_back({i*maxs+j+C, D});
    }
  }
  vector<ll> dist = dijkstra(g, S);
  vector<ll> ans(N, INF);
  REP(i, N){
    REP(j, 2500){
      ans[i] = min(ans[i], dist[i*maxs+j]);
    }
  }
  FOR(i, 1, N){
    cout << ans[i] << endl;
  }
  return 0;
}
