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

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[List[(Int, Int)]](N+1)(Nil) // (node, dist)

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

  def lte(a: (Int, Int), b: (Int, Int)): Boolean = { // <=  小さい方が強い
    if (a._1 != b._1)
      a._1 <= b._1
    else
      a._2 <= b._2
      
  }

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

  val done = new Array[Boolean](N+1)
  private[this] val pq = new PriorityQueue[((Int, Int), Int)]

  for (s <- 1 to N) {
    // init
    for (i <- 1 to N) {
      done(i) = false
    }

    // prepare


    // calc
    pq.enqueue(((0, L), s))

    while(!pq.isEmpty) {
      val ((_cnt, rest), node) = pq.dequeue()
      val cnt = -_cnt

      if (!done(node)) {
        done(node) = true
        ans(s)(node) = cnt
        for (((jinode: Int), dist) <- graph(node) if !done(jinode)) {
          val next =
            if (rest >= dist)
              (-cnt, (rest-dist))
            else
              (-(cnt+1), (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()
  }
}
