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)

  val v, M, L = in.next().toInt
  val d = Array.ofDim[Long](v+1, v+1)

  // 初期化
  val MAX = Int.MaxValue
  for(i <- 1 to v; j <- 1 to v){
    if(i == j) d(i)(j) = 0
    else d(i)(j) = MAX
  }

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

  //
  // warshall_floyd
  for(k <- 1 to v; i <- 1 to v; j <- 1 to v){
    d(i)(j) = Math.min(d(i)(j), d(i)(k) + d(k)(j))
  }

  val d2 = Array.ofDim[Long](v+1, v+1)

  // 初期化
  for(i <- 1 to v; j <- 1 to v){
    if(i == j) d2(i)(j) = 0
    else d2(i)(j) = MAX
  }

  for(i <- 1 to v; j <- 1 to v){
    if (d(i)(j) <= L) d2(i)(j) = 1
  }

  // warshall_floyd
  for(k <- 1 to v; i <- 1 to v; j <- 1 to v){
    d2(i)(j) = Math.min(d2(i)(j), d2(i)(k) + d2(k)(j))
  }

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

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()
  }
}
