program main
  implicit none
  character(len=100000) :: S
  character,allocatable:: S2(:)
  integer :: N,Q
  integer :: N2
  integer :: l,r
  integer :: i,ii
  integer :: out
  read(*,*) N,Q
  read(*,*) S(1:N)
  do i=1,Q
     read(*,*) l,r
     N2=r-l+1
     out=0
     do ii = 1,N2-1
        if ( S( l+ii-1:l+ii ) == 'AC' ) then
           out=out+1
        end if
     end do
     write(*,'(i0)') out
  end do

end program main
