#[allow(unused_imports)]
use std::cmp::Ordering;

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get {
    ([$t: ty]) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

use std::cmp::Reverse;

fn solve() {
    let (n, m, s) = get!(usize, usize, usize);
    let uvab = get!(usize, usize, usize, usize; m);
    let cd = get!(usize, usize; n);

    let mut nodes = vec![Vec::new(); n];
    for (u, v, a, b) in uvab {
        nodes[u - 1].push((v - 1, a, b));
        nodes[v - 1].push((u - 1, a, b));
    }
    const INF: usize = 1_000_000_000_000_000;
    const MAX: usize = 2500;
    let mut dist = vec![vec![INF; MAX + 1]; n];
    let mut heap = BinaryHeap::new();
    let s = min!(MAX, s);
    heap.push((Reverse(0), 0, s));
    dist[0][s] = 0;
    while let Some((Reverse(cost), node, silver)) = heap.pop() {
        for &(next, ns, nc) in &nodes[node] {
            if silver >= ns && dist[next][silver - ns] > dist[node][silver] + nc {
                dist[next][silver - ns] = dist[node][silver] + nc;
                heap.push((Reverse(dist[next][silver - ns]), next, silver - ns));
            }
        }
        let (c, d) = cd[node];
        if dist[node][min!(silver + c, MAX)] > dist[node][silver] + d {
            dist[node][min!(silver + c, MAX)] = dist[node][silver] + d;
            heap.push((
                Reverse(dist[node][min!(silver + c, MAX)]),
                node,
                min!(silver + c, MAX),
            ));
        }
    }

    for i in 1..n {
        let mut mn = INF;
        for j in 0..MAX + 1 {
            mn = min!(mn, dist[i][j]);
        }
        println!("{}", mn);
    }
}


Measured memory_bytes: 3676