INTEGER N,Q
CHARACTER(100002) S
INTEGER L,R
INTEGER,ALLOCATABLE,DIMENSION(:)::CNT
INTEGER LL,memo
READ*,N,Q
READ*,S
ALLOCATE(CNT(N+2))
CNT=0
LL=0
DO
  memo=INDEX(S(LL:),"AC")
  IF(memo==0)EXIT
  CNT(LL+memo)=CNT(LL+memo)+1
  LL=LL+memo
END DO
DO i=2,n+1
  CNT(i)=cnt(i-1) + cnt(i)
end do
DO I=1,Q
  READ*,L,R
  PRINT"(I0)",CNT(R)-CNT(L)
END DO
END