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

  read *, n, q
  read *, s

  allocate (a(n), ans(q))
  ans(:) = 0
  a(:) = 0

  do i = 1, len_trim(s) - 1
    if (s(i:i+1) == 'AC') then
      a(i+1:) = a(i+1:) + 1
    end if
  end do 

  do k = 1, q
    read *, l, r
    ans(k) = a(r) - a(l)
  end do

  do k = 1, q
    print '(i0)', ans(k)
  end do

end