program main
  implicit none
  character(len=100000) :: S
  character,allocatable:: S2(:)
  integer :: N,Q
  integer :: N2
  integer,allocatable :: l(:),r(:)
  integer :: i,ii
  integer,allocatable :: out(:),out2(:)
  read(*,*) N,Q
  read(*,*) S(1:N)
  allocate(out(N))
  out=0
  do i = 1,N-1
     if ( S( i:i+1 ) == 'AC' ) then
        out(1:i)=out(1:i)+1
     end if
  end do
  allocate(out2(N))
  out2=0
  do i = N-1,1,-1
     if ( S( i:i+1 ) == 'AC' ) then
        out2(1:i) = out2(1:i)-1
     end if
  end do
  allocate(l(Q),r(Q))
  do i=1,Q
     read(*,*) l(i),r(i)
  end do
  do i = 1,Q
     write(*,'(i0)') max( out(l(i))+out2(r(i)) ,0)
  end do
end program main
