implicit none
integer :: n,q
integer :: l,r,i,k
integer, allocatable :: c(:)
character(100000) :: s
read *,n,q
read *,s

allocate(c(0:N-1))
c(:) = 0
k = 0
i = 1
do while (i<N)
   if (s(i:i+1) == 'AC') then
      k = k + 1
      c(i) = k
      c(i+1) = k
      i = i + 2
   else if (s(i+1:i+1) /= 'A') then
      c(i) = k
      c(i+1) = k
      i = i + 2
   else
      c(i) = k
      i = i + 1
   endif
enddo

do i = 1, q
   read *,l,r
   write(6,'(i0)') c(r-1)-c(l-1)
enddo
end