program get_ac
  implicit none
  integer :: n, q, l, r, a(100000) = 0, i
  character(100000) :: s
  read(*,*) n, q
  read(*,*) s
  do i = 2, n
    a(i) = a(i-1)+merge(1,0,s(i-1:i) == "AC")
  end do
  do i = 1, q
    read(*,*) l, r
    write(*,'(i0)') a(r)-a(l)
  end do
end program get_ac