#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

struct edge {
    ll to, cost;
};

ll N;
// vector<edge> G[1000000];
VV<edge> G(1000000);
V<ll> d(1000000);

void addedge(VV<edge>& G, int st, int ed, ll co) {
    edge e;
    e.to = ed;
    e.cost = co;
    G[st].push_back(e);
}

void dijkstra(int s) {
    priority_queue<plglg, vector<plglg>, greater<plglg> > que;
    fill(d.begin(), d.end(), llmax);
    d[s] = 0;
    que.push(plglg(0, s));

    while (!que.empty()) {
        plglg p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) {
            continue;
        }
        int len = G[v].size();
        for (int i = 0; i < len; i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(plglg(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll M, S;
    cin >> N >> M >> S;
    ll NN = N;
    N = (N * 2500) + 10;
    REP(i, 0, M) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        REP(j, 0, 2500) {
            if (j - a >= 0) {
                addedge(G, u * 2500 + j, v * 2500 + j - a, b);
                addedge(G, v * 2500 + j, u * 2500 + j - a, b);
            }
        }
    }
    REP(i, 0, NN) {
        ll c, d;
        cin >> c >> d;
        REP(j, 0, 2499) {
            addedge(G, i * 2500 + j, i * 2500 + min(j + c, (ll)2499), d);
        }
    }
    dijkstra(min(S, (ll)2499));
    REP(i, 1, NN) {
        ll ans = inf;
        REP(j, 0, 2500) {
            ans = min(ans, d[i * 2500 + j]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 51156