PROGRAM ATCODER

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

read(*,*) n,q,s
do i = 1, q, 1
  count = 0
  read(*,*) l, r
  b = s(l:r)
  u = 1
  do
    t = index(b(u:),'AC')
    If (t==0) exit
    u = u + t
    count = count + 1
  end do
  write(*,'(i0)') count
end do

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

END PROGRAM ATCODER
