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

allocate(c(N-1))
c(:) = .False.
do i = 1, N-1
   if (s(i:i) == 'A' .and. s(i+1:i+1) == 'C') then
      c(i) = .True.
   endif
enddo

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