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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
#include <queue>
#define INF 1ll << 60
typedef long long ll;
ll N, M, S, amax;
VLL A(100), B(100), C(100), D(100);

struct edge {
  ll to, time_cost, coin_cost;
};
typedef pair<ll, PLL> P;

struct graph {
  ll V;
  vector<vector<edge>> G;
  VVLL d;
  VLL ans;
  graph(ll n) { init(n); }

  void init(ll _n) {
    V = _n;
    G.resize(V);
    d.resize(V);
    ans.resize(V, 1ll << 60);
    for(int i = 0; i < V; i++) {
      d[i].resize(10000, INF);
    }
  }

  void add_edge(ll s, ll t, ll time_cost, ll coin_cost) {
    edge e;
    e.to = t;
    e.time_cost = time_cost;
    e.coin_cost = coin_cost;
    G[s].push_back(e);
  }

  void dijkstra() {
    d[0][S] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, PLL(0, S)));
    while(!que.empty()) {
      P p = que.top();
      que.pop();
      ll current_v = p.second.first;
      ll current_coin = p.second.second;
      if(d[current_v][current_coin] < p.first)
        continue;
      for(auto e : G[current_v]) {
        ll coin_cost = e.coin_cost;
        ll next_coin = current_coin - coin_cost;
        if(next_coin >= 0 &&
           d[e.to][next_coin] > (d[current_v][current_coin] + e.time_cost)) {
          d[e.to][next_coin] = d[current_v][current_coin] + e.time_cost;
          que.push(P(d[e.to][next_coin], PLL(e.to, next_coin)));
        }
      };
      ll nextC = min(amax * V, current_coin + C[current_v]);
      if(current_coin < amax * V &&
         d[current_v][nextC] > (d[current_v][current_coin] + D[current_v])) {
        d[current_v][nextC] = d[current_v][current_coin] + D[current_v];
        que.push(P(d[current_v][nextC], PLL(current_v, nextC)));
      }
    }
    rep(i, N) rep(j, amax * V) { chmin(ans[i], d[i][j]); }
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M >> S;
  VLL u(M), v(M);

  graph g(N);
  rep(i, M) {
    cin >> u[i] >> v[i] >> A[i] >> B[i];
    u[i]--, v[i]--;
    g.add_edge(u[i], v[i], B[i], A[i]);
    g.add_edge(v[i], u[i], B[i], A[i]);
    chmax(amax, A[i]);
  }
  chmin(S, amax * N);

  rep(i, N) { cin >> C[i] >> D[i]; }
  g.dijkstra();
  FOR(i, 1, N) { cout << g.ans[i] << endl; }
  return 0;
}


Measured memory_bytes: 10136