object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, M, L = sc.nextInt
  val ABCs = Seq.fill(M)(sc.nextInt, sc.nextInt, sc.nextInt)
  val Q = sc.nextInt
  val STs = Seq.fill(Q)((sc.nextInt, sc.nextInt))

  def wf(a: Array[Array[Int]]) = {
    for(k <- 1 to N; i <- 1 to N; j <- 1 to N) if (a(i)(j) > a(i)(k) + a(k)(j)) a(i)(j) = a(i)(k) + a(k)(j)
  }

  val d = Array.fill(N + 1, N + 1)(L + 1)
  ABCs.foreach{case(a, b, c) => d(a)(b) = c; d(b)(a) = c}
  wf(d)
  val x = d.map(_.map{v => if(v <= L) 1 else L + 1})
  wf(x)
  STs.foreach{case(s, t) => println(if(x(s)(t) > L) -1 else x(s)(t) - 1)}
}