#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>

using edge = std::pair<int, int>;
std::vector<edge> edges[2501 * 50];
long long dist[2501 * 50];

int main()
{
	int n, m, s;
	scanf("%d%d%d", &n, &m, &s);
	for (int i = 0; i < m; ++i)
	{
		int u, v, a, b;
		scanf("%d%d%d%d", &u, &v, &a, &b);
		u = (u - 1) * 2501;
		v = (v - 1) * 2501;
		for (int j = 0; a + j <= 2500; ++j)
		{
			edges[v + a + j].emplace_back(u + j, b);
			edges[u + a + j].emplace_back(v + j, b);
		}
	}
	for (int i = 0; i < n; ++i)
	{
		int c, d;
		scanf("%d%d", &c, &d);
		if (c > 2500)
		{
			c = 2500;
		}
		int v = i * 2501;
		for (int j = 0; j + c <= 2500; ++j)
		{
			edges[v + j].emplace_back(v + j + c, d);
		}
	}

	std::fill(dist, dist + 2501 * 50, 1e18);
	dist[std::min(2500, s)] = 0;
	using P = std::pair<long long, int>;
	std::priority_queue<P, std::vector<P>, std::greater<P>> q;
	q.emplace(0, std::min(2500, s));
	while (q.size() > 0)
	{
		auto [cost, v] = q.top(); q.pop();
		if (cost > dist[v])
		{
			continue;
		}
		for (auto [to, c] : edges[v])
		{
			long long next = cost + c;
			if (dist[to] > next)
			{
				dist[to] = next;
				q.emplace(next, to);
			}
		}
	}
	for (int i = 1; i < n; ++i)
	{
		long long ans = 1e18;
		for (int j = 0; j <= 2500; ++j)
		{
			if (ans > dist[i * 2501 + j])
			{
				ans = dist[i * 2501 + j];
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}
