def cc
    n,q = gets.chomp.split(/\s/).map{|x| x.to_i}
    s = gets.chomp
    ss = []
    for i in 1..q
        l,r = gets.chomp.split(/\s/).map{|x| x.to_i}
        ss.push(s[l-1..r-1].scan(/AC+/).length)
    end

    for i in 1..q
        puts ss[i-1]
    end
end

cc