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