implicit none

integer n,q,i,left,right,j,l,r,k
character(:),allocatable:: s
integer,allocatable,dimension(:) ::counts
integer ::cnt=0

read(5,*)n,q
allocate(character(n)::s)
allocate(counts(n))
counts(:)=0

read(5,*)s

do k=1,n-1
if(s(k:k+1)=="AC") then
cnt=cnt+1
endif
counts(k)=cnt
enddo

do i=1,q
read(5,*)l,r
write(6,*) (counts(r-1)-counts(l-1))
enddo


deallocate(counts)
deallocate(s)
end
