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