let scan_int () = Scanf.scanf " %d" (fun x -> x)
let scan_string () = Scanf.scanf " %s" (fun x -> x)
let scan_array len read_func = Array.init len (fun _ -> read_func())
let print_int n = Printf.printf "%d\n" n

let max_dist = int_of_float 1e15

let warshall_floyd mat n =
  for k = 0 to n-1 do
    for i = 0 to n-1 do
      for j = 0 to n-1 do
        mat.(i).(j) <- (min mat.(i).(j) (mat.(i).(k) + mat.(k).(j)))
      done
    done
  done


let () =
  let n = scan_int() and m = scan_int() and l = scan_int() in
  let dist_mat = Array.make_matrix n n max_dist in
  let _ =
    for i = 0 to n-1 do
      dist_mat.(i).(i) <- 0
    done in
  let _ =
    for i = 0 to m-1 do
      let a = scan_int() and b = scan_int() and c = scan_int() in
      let _ = dist_mat.(a-1).(b-1) <- c in
      dist_mat.(b-1).(a-1) <- c
    done in
  let _ = warshall_floyd dist_mat n in
  let _ =
    for i = 0 to n-1 do
      for j = 0 to n-1 do
        if dist_mat.(i).(j) <= l then dist_mat.(i).(j) <- 1
        else dist_mat.(i).(j) <- max_dist
      done
    done in
  let _ = warshall_floyd dist_mat n in
  let q = scan_int() in
  for i = 0 to q-1 do
    let s = scan_int() and t = scan_int() in
    if dist_mat.(s-1).(t-1) = max_dist then print_int (-1)
    else print_int (dist_mat.(s-1).(t-1) - 1)
  done
  