/*
I am the fire that burns your skin
Soy el fuego que arde tu piel

I am the water that kills your thirst
Soy el agua que mata tu sed

The castle, the tower, I am
El castillo, la torre, yo soy

The sword that keeps the flow
La espada que guarda el caudal

You the air that I breathe
Tú el aire que respiro yo

And the moonlight on the sea
Y la luz de la luna en el mar

The throat that I want to wet
La garganta que ansio mojar

I fear drowning in love
Que temo ahogar de amor

And which desires will you give me?
¿Y cuáles deseos me vas a dar?

You say, 'my treasure just look at it'
Dices tú, 'mi tesoro basta con mirarlo'

And yours will be
Y tuyo será

And yours will be
Y tuyo será
*/
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
mt19937 R(chrono::system_clock().now().time_since_epoch().count());

vector<pair<ll, pll>> edge[55];
pll coin_time[55];
ll cost[55][3009];
ll fans[55];
int main() {
    ll n, m, s;
    ll u, v, a, b;
    FAST;
    cin >> n >> m >> s;
    for (int i = 0; i < m; i++) {
        cin >> u >> v >> a >> b;
        edge[u].EB(MP(v, MP(a, b)));
        edge[v].EB(MP(u, MP(a, b)));
    }
    for (int i = 1; i <= n; i++) {
        cin >> coin_time[i].ff >> coin_time[i].ss;
    }
    s = min(s,2600LL);
    // time , coin rem , node
    dijkstra<pair<pll, ll>> pq;
    memset(cost, inf, sizeof cost);
    memset(fans, inf, sizeof fans);
    for (int i = 0; i <= s; i++)
        cost[1][i] = 0;
    pq.push(MP(MP(0, s), 1));
    while (pq.empty() == false) {
        pair<pll, ll> t = pq.top();
        pq.pop();

        ll nodenow = t.ss;
        ll timeneeded = t.ff.ff;
        ll coin_rem = t.ff.ss;

        if (cost[nodenow][coin_rem] < timeneeded)
            continue;
        fans[nodenow] = min(fans[nodenow], timeneeded);

        for (auto i : edge[nodenow]) {
            ll to = i.ff;
            ll silvercost = i.ss.ff;
            ll destcost = timeneeded + i.ss.ss;
            if (silvercost <= coin_rem) {
                if (cost[to][coin_rem - silvercost] > destcost) {
                    cost[to][coin_rem - silvercost] = destcost;
                    pq.push(MP(MP(destcost, coin_rem - silvercost), to));
                }
            }
        }
        for (ll i = coin_rem + coin_time[nodenow].ff, j = timeneeded + coin_time[nodenow].ss; i < 2500; i += coin_time[nodenow].ff, j += coin_time[nodenow].ss) {
            if (cost[nodenow][i] > j) {
                cost[nodenow][i] = j;
                pq.push(MP(MP(j, i), nodenow));
            }
        }
    }
    for (int i = 2; i <= n; i++)
        cout << fans[i] << "\n";
}


Measured memory_bytes: 102904