program name
    implicit none
    integer(4):: n,q
    character(:),allocatable:: s
    integer(4),allocatable:: acnum(:), lr(:,:)
    integer(4):: i,j

    read*, n,q
    allocate(character(n):: s)
    read*, s
    allocate(acnum(n), lr(2,q))

    do i=1,q
        read*, lr(:,i)
    end do

    acnum(1)=0

    do i=2,n
        if (s(i-1:i) == 'AC')then
            acnum(i) = acnum(i-1)+1
        else
            acnum(i) = acnum(i-1)
        end if
    end do

    do i=1,q
        print*, acnum(lr(2,i)) - acnum(lr(1,i))
    end do

end program name