PROGRAM ATCODER

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

read(*,*) n,q,s

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

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

do i = 2, n
  do j = 1, n/2
    if(i >= c(j))then
      count(i) = count(i) + 1
    end if
  end do
end do

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

contains
!!!!!! サブルーチンは↓
!!!!!!

END PROGRAM ATCODER
