program ccc
implicit none

integer :: n, q, ln, i, j
character(100001) :: s
integer,allocatable,dimension(:) :: a, l, r

read*, n, q
read*, s
s=trim(s)
ln=len_trim(s)
allocate(a(0:ln),l(q),r(q))
do i=1, q
read*, l(i), r(i)
end do

j=0
do i=1,n-1
if(s(i:i)=='A'.and.s(i+1:i+1)=='C') j=j+1
a(i)=j
end do
a(0)=0
a(n)=a(n-1)

do i=1,q
write(*,'(i0)') a(r(i)-1)-a(l(i)-1)
end do

end program