PROGRAM ATCODER

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

read(*,*) n,q,s
do i = 1, q, 1
  b = ''
  count = 0
  read(*,*) l, r
  b = s(l:r)
  do j = 1, len_trim(b)-1
    if ( b(j:j) == 'A' .and. b(j+1:j+1) == 'C' ) then
      count = count + 1
    end if
  end do
  write(*,'(i0)') count
end do

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

END PROGRAM ATCODER
