PROGRAM ATCODER

implicit none
integer(16) :: n,q,i,j,l,r,t,ans
character(len=10**5) :: s,b
integer,allocatable :: c(:),count(:)

read(*,*) n,q,s

allocate(c(n/2),count(n))
c = n+1

t = 1
do i = 1, n/2
  j = index(s(t:),'AC')
  If (j==0) exit
  c(i) = t+j
  t = t + j
end do

do i = 1, q
  ans = 0
  read(*,*) l,r
  do j = 1,n/2
    if ( c(j) > l .and. c(j) <= r ) then
      ans = ans + 1
    end if
  end do
  write(*,'(i0)') ans
end do
  
contains
!!!!!! サブルーチンは↓
!!!!!!

END PROGRAM ATCODER
