program prob3
    implicit none
    integer::i,cnt,le,N,Q,l,r
    integer, allocatable::c(:)
    character(len=100005)::S
    read(*,*) N,Q
    read(*,*) S
    le = len_trim(S)
    allocate(c(le))

    cnt = 0
    do i = 2, le
        if(S(i-1:i-1) .eq. "A" .and. S(i:i) .eq. "C") then
            cnt = cnt + 1
        end if
        c(i) = cnt
    end do

    do i = 1, Q
        read(*,*) l, r
        write(*,*) c(r) - c(l)
    end do
end program