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

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

  val N, M, L = in.next().toInt
  val graph = Array.fill[Seq[Int]](N+1)(Nil) // (node)
  val mat = Array.ofDim[Int](N+1, N+1)

  for (_ <- 1 to M) {
    val a, b, c = in.next().toInt
    if(c <= L) {
      graph(a) = b +: graph(a)
      graph(b) = a +: graph(b)

      mat(a)(b) = c
      mat(b)(a) = c
    }
  }

  // 
  val ans = Array.ofDim[Long](N+1, N+1)
  for (y <- 1 to N; x <- 1 to N)
      ans(y)(x) = -1

  val done = new Array[Boolean](N+1)
  private[this] val pq = new PriorityQueue[(Long, Int)]
  val base = 1e10.toLong

  for (s <- 1 to N) {
    // init
    for (i <- 1 to N) {
      done(i) = false
    }
    if(!pq.isEmpty)
      pq.clear()


    // prepare


    // calc
    pq.enqueue((L, s))
    var fuga = N

    while(fuga != 0 && !pq.isEmpty) {
      val (hoge, node) = pq.dequeue()
      val rest = (hoge+ 500L * base) % base
      val cnt = -((hoge-rest) / base)
      // println(rest,cnt, (s, node))

      if (!done(node)) {
        done(node) = true
        ans(s)(node) = cnt
        fuga -= 1

        for (jinode <- graph(node) if !done(jinode)) {
          val dist = mat(node)(jinode)
          val next =
            if (rest >= dist)
              -cnt * base + (rest-dist)
            else
              -(cnt+1)*base + (L-dist)
          pq.enqueue((next, jinode))
        }
      }
    }

  }

  
  //
  val Q = in.next().toInt
  for (_ <- 1 to Q) {
    val s, t = in.next().toInt
    pw.println(ans(s)(t))
  }
  pw.flush()
}


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