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

read(*,*) n, q
read(*,*) s(1:n)
allocate( l(q), r(q) )
do i = 1, q
   read(*,*) l(i), r(i)
   j = 0
   do k = l(i), r(i)-1
      if( s(k:k+1) == 'AC' ) then
         j = j+1
      end if
   end do
   write(*,'(i0)') j
end do


end program main
