program main
implicit none
integer :: n,q,l,r
character(len=10*5) :: s
integer :: i,j,k,nc

read(*,*) n,q
read(*,*) s(1:n)

do k = 1, q
   read(*,*) l,r
   nc = 0
    i = l
  do
    j = index(s(i:),'AC')
    If (j==0) exit
    i = i + j
    If (i>r) exit
    nc = nc+1
  end do
  write(*,'(i0)') nc
end do



end program main
