
object Main extends App {
  var f = readLine.split(" ").map(_.toInt)
  var n = f(0)
  var m = f(1)
  var l = f(2)

  var inputs = for(i <- 0 until m) yield readLine

  var ways = inputs.map(_.split(" ")(2)).map(_.toInt)
  var q = readInt

  def count(way:Array[Int]) :Int =  {
    var s = way(0)
    var t = way(1)
    import scala.math.{min, max}
    var low = min(s, t) - 1
    var up = max(s, t) - 1
    if(ways.length == 0) {
      return -1
    }
    var maveway = ways.slice(low, up).sorted
    var cl = l
    def calc(i:Int, cl:Int, c:Int):Int = {
        if(maveway.length == i) 
           c
       else if(maveway(i) <= l) {
            if(maveway(i) <= cl) {
                calc(i + 1, cl - maveway(i), c)
            } else {
                calc(i + 1, cl + l - maveway(i), c + 1)
            }
        } else {
            -1
        }

    }

    calc(0, cl, 0)

  }

  var sts = for(i <- 0 until q) yield readLine.split(" ").map(_.toInt)
  for(p <- sts)
     println(count(p))

}