PROGRAM ATCODER

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

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

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

END PROGRAM ATCODER
