program get_ac
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,q,i,l,r
    integer(int32), allocatable:: cs(:), ans(:)
    character(:),allocatable:: s

    read*, n,q
    allocate(cs(n),ans(q),source=0)
    allocate(character(n):: s)

    read*, s
    do i=2,n
        cs(i)=cs(i-1)
        if (s(i-1:i) == 'AC') cs(i)=cs(i)+1
    end do
    
    do i=1,q
        read*, l,r
        ans(i) = cs(r)-cs(l)
    end do

    do i=1,q
        print'(i0)', ans(i)
    end do
end program get_ac