#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

void chmin(Int& a, Int b) { if (a > b) { a = b; } };

int main() {
	constexpr Int INF = 1e18;
	constexpr Int maxS = 2500;
	Int N, M, S;
	cin >> N >> M >> S;
	vector<vector<tuple<int, int, Int>>> g(N);
	for (int i = 0; i < M; ++i) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		--u; --v;
		g[u].emplace_back(v, a, b);
		g[v].emplace_back(u, a, b);
	}
	vector<Int> C(N), D(N);
	for (int i = 0; i < N; ++i) {
		cin >> C[i] >> D[i];
	}

	vector<vector<Int>> d(N, vector<Int>(maxS + 1, INF));
	d[0][min(S, maxS)] = 0;
	priority_queue<pair<Int, int>, vector<pair<Int, int>>, greater<pair<Int, int>>> que;
	que.emplace(0, min(S, maxS));
	while (!que.empty()) {
		auto p = que.top(); que.pop();
		Int cost = p.first;
		int u = p.second / 10000;
		int s = p.second % 10000;

		if (s < maxS) {
			int nxs = min(maxS, s + C[u]);
			if (d[u][nxs] > d[u][s] + D[u]) {
				d[u][nxs] = d[u][s] + D[u];
				que.emplace(d[u][nxs], u*10000 + nxs);
			}
		}
		for (auto t : g[u]) {
			int v = get<0>(t);
			int a = get<1>(t);
			Int b = get<2>(t);

			if (s - a < 0 || d[v][s - a] <= d[u][s] + b) {
				continue;
			}
			d[v][s - a] = d[u][s] + b;
			que.emplace(d[v][s - a], v*10000 + (s - a));
		}
	}

	for (int i = 1; i < N; ++i) {
		Int ans = INF;
		for (auto val : d[i]) { ans = min(ans, val); }
		cout << ans << endl;
	}

	return 0;
}
