program main
  implicit none
  character(len=100000) :: s
  integer :: n, q, i, j, k, l, r
  integer, allocatable :: ans(:)

  read *, n, q
  read *, s

  allocate (ans(q))
  ans(:) = 0

  do k = 1, q
    read *, l, r
    i = 1
    do i = l, r, 2
      if (index(s(i:r),'AC') > 0) then
        ans(k) = ans(k) + 1
      end if
    end do
  end do
  do k = 1, q
    print '(i0)', ans(k)
  end do

end