n, q = gets.chomp!.split(" ").map!(&:to_i)
s = gets.chomp!
l = Array.new(0, q)
r = Array.new(0, q)

q.times do |i|
    l[i], r[i] = gets.chomp!.split(" ").map!(&:to_i)
end

memo = {}
(n - 1).times do |i|
    if s[i] == 'A' && s[i + 1] == "C"
        memo[i] = 1
    else
        memo[i] = 0
    end
end


q.times do |i|
    count = 0
    (l[i]-1).upto(r[i]-2) do |i|
        count += memo[i]
    end

    puts count
end
