program main
	implicit none
	integer :: N, Q, i
	character(100010) :: S
	integer, allocatable :: l(:), r(:), temp1(:), temp2(:)
	read(*, *) N, Q
	read(*, *) S(1:N)
	allocate(l(1:Q), r(1:Q), temp1(1:N), temp2(1:N+1))
	do i = 1, Q
		read(*, *) l(i), r(i)
	end do
	
	temp1(1) = 0
	do i = 1, N-1
		if(S(i:i+1) == "AC") then
			temp1(i+1) = temp1(i) + 1
		else
			temp1(i+1) = temp1(i)
		end if
	end do
	
!	temp2(N) = 0
!	do i = N, 2, -1
!		if(S(i-1:i) == "AC") then
!			temp2(i-1) = temp2(i) + 1
!		else
!			temp2(i-1) = temp2(i)
	!	end if
!	end do
!	temp1 = abs(temp1 - temp2)
!	write(*, *) temp1
	
	do i = 1, Q
		write(*, *) temp1(r(i)) - temp1(l(i))
	end do
end program main