#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
    for (auto &e : t) fill(e, v);
}
// auto v = make_vec<int>(h, w);
// fill(v, 0);
const int INF = 1LL << 60;

struct edge{ 
  int to, cost, time;
  bool operator<(const edge& a) const {
    return time > a.time;
  }
 };

signed main(){

  int n, m, s; cin >> n >> m >> s;
  vector<vector<edge>> g(n);
  vector<int> a(m), b(m), c(n), d(n);
  for(int i = 0; i < m; i++){
    int u, v; cin >> u >> v;
    u--, v--;
    cin >> a[i] >> b[i];
    g[u].push_back({v, a[i], b[i]});
    g[v].push_back({u, a[i] ,b[i]});
  }
  for(int i = 0; i < n; i++){
    cin >> c[i] >> d[i];

  }

  auto dp = make_vec<int>(n, n * 55);
  fill(dp, INF);
  priority_queue<edge> q; //最小値
  q.push({0, s, 0});
  dp[0][s] = 0;
  while(!q.empty()){
    edge p = q.top(); q.pop();
    int u = p.to, cost = p.cost, t = p.time;
    if(dp[u][cost] < t) continue;
    if(cost + c[u] < n*50 && dp[u][cost + c[u]] > dp[u][cost] + d[u]){
      dp[u][cost + c[u]] = dp[u][cost] + d[u];
      q.push({u, cost + c[u], dp[u][cost + c[u]]});
    }
    for(auto e : g[u]){
      if(cost - e.cost >= 0 && dp[e.to][cost - e.cost] > dp[u][cost] + e.time){
        dp[e.to][cost - e.cost] = dp[u][cost] + e.time;
        q.push({e.to, cost - e.cost, dp[e.to][cost - e.cost]});
      }
    }
  }

  for(int i = 1; i < n; i++){
    //cout << dp[i] << endl;
    cout << *min_element(dp[i].begin(), dp[i].end()) << endl;
  }

  return 0;
}