import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  case class Edge(to: Int, fee: Int, time: Long)

  case class Node(num: Int, time: Long)

  val N, M, _S = in.next().toInt
  val graph = Array.fill[List[Edge]](N+1)(Nil)
  val nodes = new Array[Node](N+1)
  for (i <- 1 to M) {
    val u, v, a, b = in.next().toInt
    val edge = 
    graph(u) = Edge(v, a, b) :: graph(u)
    graph(v) = Edge(u, a, b) :: graph(v)
  }
  for (i <- 1 to N) {
    val c, d = in.next().toInt
    nodes(i) = Node(c, d)
  }

  val sMax = 2500
  val S = Math.min(_S, sMax)


  //
  val MAX = Long.MaxValue

  val dist = Array.ofDim[Long](N+1, sMax+1) // from からの距離を格納する
  for (i <- 1 to N; j <- 0 to sMax)
    dist(i)(j) = MAX

  val check = Array.ofDim[Boolean](N+1, sMax+1)  // すでにその頂点からを調べたかのフラグ

  dist(1)(S) = 0

  val pq = new PriorityQueue[(Long, (Int, Int))]  // (-cost, node) queue
  pq.enqueue((-0, (S, 1)))

  // 頂点は v 個あるので、v 周する
  for(_ <- 0 until N * 2500) {
    // 調べ済みでない頂点のうち、最も近い頂点を now に入れる
    var nowNode = -1       // このターンにフォーカスするノード
    var ginka = -1
    var nowTime = -1L

    breakable {
      while(!pq.isEmpty) {
        val (_time, (_ginka, nodeNum)) = pq.dequeue
        nowNode = nodeNum
        ginka = _ginka
        nowTime = -_time
        if(!check(nowNode)(ginka)){  // まだチェックされていないノードだったら決定
          check(nowNode)(ginka) = true
          break
        }
      }
    }

    if (nowNode != -1) {
      val node = nodes(nowNode)
      if (ginka < sMax) {
        val nextTime = nowTime + node.time
        val nextGinka = (ginka + node.num) min sMax
        dist(nowNode)(nextGinka) = dist(nowNode)(nextGinka) min nextTime

        pq.enqueue((-nextTime, (nextGinka, nowNode)))
      }

      // その頂点からたどり着ける頂点の情報を更新する
      for(Edge(nextNode, fee, time) <- graph(nowNode)) {
        val nextTime = nowTime + time
        val nextGinka = ginka - fee

        if(nextGinka >= 0 && nextTime < dist(nextNode)(nextGinka)){  // 既存の通路より近いなら更新
          dist(nextNode)(nextGinka) = nextTime
          pq.enqueue((-nextTime, (nextGinka, nextNode)))
        }
      }
    }
  }

  for (i <- 2 to N) {
    pw.println(dist(i).min)
  }
  pw.flush()
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
