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))

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

c = 0
do i = 2,n
  if ( s(i-1:i-1) == 'a' ) then
    c(i) = c(i-1) + 1
  else
    c(i) = c(i-1)
  end if
end do

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

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

END PROGRAM ATCODER
