PROGRAM ATCODER

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

read(*,*) n,q,s

allocate(c(n))
c = 0

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


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

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

END PROGRAM ATCODER
