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

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

do i = 1, q
   read(*,*) l(i), r(i)
   write(*,'(i0)') sum( t(l(i):r(i)-1) )
end do

end program main
