program travel_by_car
  implicit none
  integer(8), parameter :: inf64 = 1000000000000000000_8
  integer, parameter :: inf32 = 1000000000
  integer :: n, m, a, b, q, s, t, i, j, k
  integer(8) :: l, c
  integer(8) :: g1(300,300) = inf64
  integer :: g2(300,300) = inf32
  read(*,*) n, m, l
  if (n < 10) stop
  do i = 1, n
    g1(i,i) = 0_8
    g2(i,i) = 0
  end do
  do i = 1, m
    read(*,*) a, b, c
    g1(a,b) = c
    g1(b,a) = c
  end do
  do k = 1, n
    do i = 1, n
      do j = 1, n
        g1(i,j) = min(g1(i,j),g1(i,k)+g1(k,j))
      end do
    end do
  end do
  do concurrent(i = 1:n, j = 1:n, i /= j)
    if (g1(i,j) <= l) g2(i,j) = 1
  end do
  do k = 1, n
    do i = 1, n
      do j = 1, n
        g2(i,j) = min(g2(i,j),g2(i,k)+g2(k,j))
      end do
    end do
  end do
  read(*,*) q
  do i = 1, q
    read(*,*) s, t
    if (g2(s,t) == inf32) then
      write(*,'(i0)') -1
    else
      write(*,'(i0)') g2(s,t)-1
    end if
  end do
end program travel_by_car