program main
implicit None
	character(len = 100000)::s
	integer(8)::n,q,i
	integer(8),allocatable::l(:),r(:),a(:)
	
	read*,n,q
	read*,s
	
	allocate(l(q),r(q),a(n))
	
	a =0
	do i = 2,n
		if(s(i:i) == "C")then
			if(s(i-1:i-1) == "A")then
				a(i) = 1
			endif
		endif
	enddo
	
	do i = 2,n
		a(i) = a(i-1)+a(i)
	enddo
	
	do i = 1,q
		read*,l(i),r(i)
	enddo
	
	do i = 1,q
		print"(i0)",a(r(i))-a(l(i))
	enddo
end program main