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

long long n, m, s, u, v, z;
long long d[51][2500];
const long long INF = 1e18;

struct edge {
	long long to, c, tm;
};

vector<edge> G[51];
typedef tuple<long long, long long, long long> P;
priority_queue<P, vector<P>, greater<P>> Q;

int main()
{
	cin >> n >> m >> s;

	fill((long long*)d, (long long*)(d + n + 1), INF);

	for (int i = 0; i < m; i++) {
		edge e;
		cin >> u >> v >> e.c >> e.tm;

		e.to = v;
		G[u].push_back(e);
		e.to = u;
		G[v].push_back(e);

		z = max(z, e.c);
	}

	z *= n - 1;
	s = min(s, z);

	for (int i = 1; i <= n; i++) {
		long long c, d;
		cin >> c >> d;

		edge e;
		e.to = i;
		e.c = -c;
		e.tm = d;
		G[i].push_back(e);
	}

	d[1][s] = 0;
	Q.push(P(0, s, 1));

	while (!Q.empty()) {
		P p = Q.top();
		Q.pop();

		int ut = get<2>(p), uc = get<1>(p);

		if (d[ut][uc] < get<0>(p))
			continue;

		for (edge e : G[ut]) {
			long long uw = uc - e.c;

			uw = min(uw, z);

			if (uw < 0)
				continue;

			if (d[e.to][uw] > d[ut][uc] + e.tm) {
				d[e.to][uw] = d[ut][uc] + e.tm;
				Q.push(P(d[e.to][uw], uw, e.to));
			}
		}
	}

	for (int i = 2; i <= n; i++) {
		long long mn = INF;
		for (int j = 0; j <= z; j++)
			mn = min(mn, d[i][j]);

		cout << mn << endl;
	}
}
