#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]
use proconio::input;
use proconio::marker::*;

use std::cmp::*;
use std::collections::binary_heap::BinaryHeap;
#[derive(Copy, Clone, Eq, PartialEq)]
struct GraphEdge {
    node_to: usize,
    cost: isize,
}
impl Ord for GraphEdge {
    fn cmp(&self, other: &GraphEdge) -> Ordering {
        other.cost.cmp(&self.cost)
    }
}
impl PartialOrd for GraphEdge {
    fn partial_cmp(&self, other: &GraphEdge) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}
impl GraphEdge {
    fn new(node_to: usize, cost: isize) -> Self {
        Self { node_to, cost }
    }
}
struct Graph {
    pub edges: Vec<Vec<GraphEdge>>,
    pub nodes: usize,
}
impl Graph {
    fn new(nodes: usize) -> Self {
        Self {
            edges: vec![vec![]; nodes],
            nodes,
        }
    }
    fn edge_undirected(&mut self, node_a: usize, node_b: usize) {
        self.edges[node_a].push(GraphEdge::new(node_b, 1));
        self.edges[node_b].push(GraphEdge::new(node_a, 1));
    }
    fn edge_directed(&mut self, node_from: usize, node_to: usize) {
        self.edges[node_from].push(GraphEdge::new(node_to, 1));
    }
    fn edge_undirected_costed(&mut self, node_a: usize, node_b: usize, cost: isize) {
        self.edges[node_a].push(GraphEdge::new(node_b, cost));
        self.edges[node_b].push(GraphEdge::new(node_a, cost));
    }
    fn edge_directed_costed(&mut self, node_from: usize, node_to: usize, cost: isize) {
        self.edges[node_from].push(GraphEdge::new(node_to, cost));
    }
    fn dijkstra(&self, node_from: usize) -> Vec<isize> {
        let mut costs = vec![std::isize::MAX; self.nodes];
        let mut heap: BinaryHeap<GraphEdge> = BinaryHeap::new();
        heap.push(GraphEdge::new(node_from, 0));
        while let Some(GraphEdge { cost, node_to }) = heap.pop() {
            if cost >= costs[node_to] {
                continue;
            }
            costs[node_to] = cost;
            for edge in &self.edges[node_to] {
                let next = GraphEdge::new(edge.node_to, cost + edge.cost);
                heap.push(next);
            }
        }
        costs
    }
}

const A_MAX: usize = 2500;

fn main() {
    input! {
        n: usize,
        m: usize,
        s: usize,
        edges: [(Usize1, Usize1, usize, usize); m],
        exchs: [(usize, usize); n],
    }
    let s = std::cmp::min(A_MAX, s);
    let mut graph = Graph::new(n * (A_MAX + 1));
    for (left, right, fare, time) in &edges {
        for i in *fare..=A_MAX {
            graph.edge_directed_costed(
                *left * (A_MAX + 1) + i,
                *right * (A_MAX + 1) + i - fare,
                *time as isize,
            );
            graph.edge_directed_costed(
                *right * (A_MAX + 1) + i,
                *left * (A_MAX + 1) + i - fare,
                *time as isize,
            );
        }
    }
    for (index, (coins, time)) in exchs.iter().enumerate() {
        for i in 0..=(A_MAX - *coins) {
            graph.edge_directed_costed(
                index * (A_MAX + 1) + i,
                index * (A_MAX + 1) + i + *coins,
                *time as isize,
            );
        }
    }
    let costs = graph.dijkstra(s);
    let costs_min: Vec<_> = (1..n)
        .map(|city| {
            costs[(city * (A_MAX + 1))..((city + 1) * (A_MAX + 1))]
                .iter()
                .min()
                .unwrap()
        })
        .copied()
        .collect();
    
    for ans in &costs_min {
        println!("{}", ans);
    }
}


Measured memory_bytes: 24700