let () = Scanf.scanf "%d %d %d\n" @@ fun n m l ->
  let dp = Array.make_matrix n n 1145141919810 in
  for i = 1 to m do
    Scanf.scanf "%d %d %d\n" @@ fun a b c ->
      dp.(a - 1).(b - 1) <- c;
      dp.(b - 1).(a - 1) <- c;
  done;
  for i = 0 to n - 1 do
    dp.(i).(i) <- 0;
  done;
  for k = 0 to n - 1 do
    for i = 0 to n - 1 do
      for j = 0 to n - 1 do
        dp.(i).(j) <- min dp.(i).(j) (dp.(i).(k) + dp.(k).(j))
      done
    done
  done;
  for i = 0 to n - 1 do
    for j = 0 to n - 1 do
      dp.(i).(j) <-
        if i = j then 0
        else if dp.(i).(j) <= l then 1
        else 1145141919810
    done
  done;
  for k = 0 to n - 1 do
    for i = 0 to n - 1 do
      for j = 0 to n - 1 do
        dp.(i).(j) <- min dp.(i).(j) (dp.(i).(k) + dp.(k).(j))
      done
    done
  done;
  Scanf.scanf "%d\n" @@ fun q ->
    for i = 1 to q do
      Printf.printf "%d\n" @@
      Scanf.scanf "%d %d\n" @@ fun s t ->
        if dp.(s - 1).(t - 1) = 1145141919810 then -1
        else dp.(s - 1).(t - 1) - 1
    done

