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
      j = index(s(l+i-1:r),'AC')
      if (j==0) exit
      ans(k) = ans(k) + 1
      i = i + j
    end do
  end do
  do k = 1, q
    print '(i0)', ans(k)
  end do

end