READ*,N,Q
READ*,S
ALLOCATE(CNT(N))
CNT=0
LL=0
DO
  IF(INDEX(S(LL:),"AC")==0)THEN
    EXIT
  ELSE
  CNT(LL+INDEX(S(LL:),"AC")-1)=1
  LL=LL+INDEX(S(LL:),"AC")
  ENDIF
END DO
DO I=1,Q
  READ*,L,R
  PRINT"(I0)",SUM(CNT(L:R-1))
END DO
END