#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N,M,S;
	cin>>N>>M>>S;
	vector<vector<array<int,3>>> adj(N);
	rep(i,0,M) {
		int u,v,a,b;
		cin>>u>>v>>a>>b;
		u--,v--;
		adj[u].push_back({v,a,b});
		adj[v].push_back({u,a,b});
	}

	vector<int> C(N),D(N);
	rep(i,0,N) cin>>C[i]>>D[i];

	const int maxs=2500;
	const ll inf=(ll)1e18;
	vector<array<ll,maxs+1>> dist(N);
	rep(i,0,N) fill(dist[i].begin(),dist[i].end(),inf);
	S=min(S,maxs);
	dist[0][S]=0;
	using state=tuple<ll,int,int>;
	priority_queue<state,vector<state>,greater<state>> q;
	q.emplace(0,0,S);
	vector<ll> res(N,inf);
	while (!q.empty()) {
		ll d;
		int v,s;
		tie(d,v,s)=q.top();
		q.pop();
		if (d!=dist[v][s]) continue;
		res[v]=min(res[v],d);

		// buy silver coins
		for (ll i=1; s+i*C[v]<=maxs; ++i) {
			int ns=(int)(s+i*C[v]);
			ll nd=d+i*D[v];
			if (dist[v][ns]>nd) {
				dist[v][ns]=nd;
				q.emplace(nd,v,ns);
			}
		}

		// go to other city
		fore(adj[v],[u,a,b]) {
			int ns=s-a;
			ll nd=d+b;
			if (ns>=0 && dist[u][ns]>nd) {
				dist[u][ns]=nd;
				q.emplace(nd,u,ns);
			}
		}
	}

	rep(i,1,N) cout<<res[i]<<'\n';
}
