
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

ll N, M, S;
ll dist[55][2600];
vector<vector<ll>>E[55];
ll C[55], D[55];
ll MX = 2550;

void dijkstra() {
	min_priority_queue<vector<ll>>q;
	//dist,city,state
	for (int i = 0; i < 55; i++) {
		for (int j = 0; j < 2600; j++) {
			dist[i][j] = inf;
		}
	}
	q.push({0,0,min(S,MX)});
	dist[0][min(S, MX)] = 0;
	while (q.size()) {
		auto v = q.top();
		q.pop();
		ll d = v[0];
		int city = v[1];
		int curmoney = v[2];
		if (dist[city][curmoney] < d)continue;
		fore(x, E[city]) {
			int to = x[0];
			int money = x[1];
			ll cost = x[2];
			if (money > curmoney)continue;
			if (curmoney < MX) {
				if (d + cost < dist[to][curmoney - money]) {
					dist[to][curmoney - money] = d + cost;
					q.push({dist[to][curmoney - money],to,curmoney-money});
				}
			}
			else {
				if (d + cost < dist[to][MX]) {
					dist[to][MX] = d + cost;
					q.push({ dist[to][MX],to,MX });
				}
			}
		}
		if (curmoney < MX){
			if (d + D[city] < dist[city][min(MX, curmoney + C[city])]) {
				dist[city][min(MX, curmoney + C[city])] = d + D[city];
				q.push({ d + D[city],city,min(MX,curmoney + C[city]) });
			}
		}
	}
}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> N >> M >> S;
	for (int i = 0; i < M; i++) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		u--, v--;
		E[u].pb({ v,a,b });
		E[v].pb({ u,a,b });
	}
	for (int i = 0; i < N; i++)cin >> C[i] >> D[i];

	dijkstra();
	for (int i = 1; i < N; i++) {
		ll tmp = inf;
		for (int j = 0; j < 2600; j++)tmp = min(tmp,dist[i][j]);
		puts(tmp);
	}
	
	return 0;
}