#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b)
{
	ll res = 1;
	a %= mod;
	assert(b >= 0);
	for (; b; b >>= 1)
	{
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
	}
	return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

static uint MD = mod;
struct ModInt
{
	using M = ModInt;
	uint v;
	ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
	M &set_v(uint _v)
	{
		v = (_v < MD) ? _v : _v - MD;
		return *this;
	}
	explicit operator bool() const { return v != 0; }
	M operator-() const { return M() - *this; }
	M operator+(const M &r) const { return M().set_v(v + r.v); }
	M operator-(const M &r) const { return M().set_v(v + MD - r.v); }
	M operator*(const M &r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
	M operator/(const M &r) const { return *this * r.inv(); }
	M &operator+=(const M &r) { return *this = *this + r; }
	M &operator-=(const M &r) { return *this = *this - r; }
	M &operator*=(const M &r) { return *this = *this * r; }
	M &operator/=(const M &r) { return *this = *this / r; }
	bool operator==(const M &r) const { return v == r.v; }
	M pow(ll n) const
	{
		M x = *this, r = 1;
		while (n)
		{
			if (n & 1)
				r *= x;
			x *= x;
			n >>= 1;
		}
		return r;
	}
	M inv() const { return pow(MD - 2); }
	friend ostream &operator<<(ostream &os, const M &r) { return os << r.v; }
};
using Mint = ModInt;
//head
// cin >> t;
// for (int cas = 1; cas <= t; ++cas)
// {
// 	cout << "Case #" << cas << ": ";
// }

struct Node {
	ll min_time[10001];
	ll ans;
	Node() {
		memset(min_time,-1,sizeof(min_time));
		ans = LONG_LONG_MAX;
	}
}nodes[50];

struct Edge {
	int to;
	ll a,b;
};

int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	ll s;
	int u,v;
	ll a,b;
	cin>>n>>m>>s;
	vector<ll> c(n),d(n);
	vector<vector<Edge>> G(n, vector<Edge>());
	rep(i,0,m) {
		cin>>u>>v>>a>>b;
		u--; v--;
		G[u].push_back(Edge{v,a,b});
		G[v].push_back(Edge{u,a,b});
	}
	rep(i,0,n) {
		cin>>c[i]>>d[i];
	}
	queue<int> q;
	if(s>=10000) s=10000;
	nodes[0].min_time[s] = 0;
	nodes[0].ans=0;
	rep(i,0,10001) {
		if(nodes[0].min_time[i]!=-1) {
			int dd = i+c[0] > 10000 ? 10000:i+c[0];
			if(nodes[0].min_time[dd]==-1 || nodes[0].min_time[i]+ d[0] < nodes[0].min_time[dd]) {
				nodes[0].min_time[dd] = nodes[0].min_time[i] + d[0];
			}
			if(i+c[0] >=10000) break;
		}
	}
	q.push(0);
	vi vis(n,0);
	vis[0]=1;

	while(!q.empty()) {
		int ii = q.front();
		q.pop();
		vis[ii]=0;
		for(Edge e: G[ii]) {
			bool flag = false;
			int jj = e.to;
			rep(i,e.a,10001) {
				if(nodes[ii].min_time[i]!=-1) {
					int dd = i-e.a;
					if(nodes[jj].min_time[dd]==-1 || nodes[ii].min_time[i]+ e.b < nodes[jj].min_time[dd]) {
						nodes[jj].min_time[dd] = nodes[ii].min_time[i]+ e.b;
						nodes[jj].ans = min(nodes[jj].min_time[dd], nodes[jj].ans);
						flag = true;
					}
				}
			}
			rep(i,0,10001) {
				if(nodes[jj].min_time[i]!=-1) {
					int dd = i+c[jj] > 10000 ? 10000:i+c[jj];
					if(nodes[jj].min_time[dd]==-1 || nodes[jj].min_time[i]+ d[jj] < nodes[jj].min_time[dd]) {
						nodes[jj].min_time[dd] = nodes[jj].min_time[i] + d[jj];
						nodes[jj].ans = min(nodes[jj].min_time[dd], nodes[jj].ans);
						flag = true;
					}
					if(i+c[jj] >=10000) break;
				}
			}
			if(flag && !vis[e.to]) {
				q.push(e.to);
				vis[e.to]=1;
			}
		}
	}

	rep(i,1,n) {
		cout<<nodes[i].ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 7596