implicit none
integer :: n,q
integer :: l,r,i
logical, allocatable :: c(:)
character(100000) :: s
read *,n,q
read *,s

allocate(c(N-1))
c(:) = .False.
i = 1
do while (i < N)
   if (s(i+1:i+1) == 'T' .or. s(i+1:i+1) == 'G') then
      i = i + 2
      cycle
   else if (s(i+1:i+1) == 'A') then
      i = i + 1
      cycle
   else if (s(i:i) == 'A') then
      c(i) = .True.
   endif
   i = i + 2
enddo

do i = 1, q
   read *,l,r
   write(6,'(i0)') count(c(l:r-1))
enddo
end