#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 60;
const int N = (int)57;
const int MAXN = (int)3e3 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e17;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

LL d[N][MAXN];
int n, m, s, c[N], tmm[N];
vector <pair<int, pair<int, int>>> gr[N];

void solve() {
	cin >> n >> m >> s;
	for (int i = 0; i < m; i++) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		u--, v--;
		gr[u].push_back(mp(v, mp(a, b)));
		gr[v].push_back(mp(u, mp(a, b)));
	}
	for (int i = 0; i < n; i++)
		cin >> c[i] >> tmm[i];
	s = min(s, MAXN - 1);
	for (int i = 0; i < N; i++)
		fill(d[i], d[i] + MAXN, LINF);
	d[0][s] = 0;
	set <pair<LL, pair<int, int>>> q;
	q.insert(mp(0, mp(0, s)));
	while (!q.empty()) {
		auto cur = *q.begin();
		q.erase(q.begin());
		int u, sil;
		tie(u, sil) = cur.second;
		for (auto e : gr[u]) {
			int v = e.first, cost = e.second.first, tim = e.second.second;
			if (cost > sil)
				continue;
			if (d[v][sil - cost] > d[u][sil] + tim) {
				q.erase(mp(d[v][sil - cost], mp(v, sil - cost)));
				d[v][sil - cost] = d[u][sil] + tim;
				q.insert(mp(d[v][sil - cost], mp(v, sil - cost)));
			}
		}
		for (int i = sil, sec = 0; i < MAXN; i += c[u], sec++) {
			if (d[u][i] > d[u][sil] + 1LL * tmm[u] * sec) {
				q.erase(mp(d[u][i], mp(u, i)));
				d[u][i] = d[u][sil] + 1LL * tmm[u] * sec;
				q.insert(mp(d[u][i], mp(u, i)));
			}
		}
	}
	for (int i = 1; i < n; i++) {
		LL ans = LINF;
		for (int j = 0; j < MAXN; j++)
			uin(ans, d[i][j]);
		cout << ans << endl;
	}
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 14076