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

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

end program main
