program main
  implicit none
  integer :: n, q, l, r, i, j
  character(100000) :: s
  integer, allocatable :: is_a_of_ac(:)

  read (*, *) n, q
  allocate (is_a_of_ac(0:n - 1))
  read (*, *) s

  is_a_of_ac(0) = 0
  do i = 1, n - 1
    if (s(i:i + 1) == "AC") is_a_of_ac(i) = 1
    is_a_of_ac(i) = is_a_of_ac(i) + is_a_of_ac(i - 1)
  end do

  do j = 1, q
    read (*, *) l, r
    write (*, "(i0)") is_a_of_ac(r - 1) - is_a_of_ac(l - 1)
  end do
end program main
