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 = { -1 => 0 }
(n - 1).times do |i|
    if s[i] == 'A' && s[i + 1] == "C"
        memo[i] = memo[i - 1] + 1 
    else
        memo[i] = memo[i - 1]
    end
end
memo[n-1] = memo[n-2]
memo[n] = memo[n-1]

#require 'pp'
#pp memo

q.times do |i|
    puts memo[r[i] - 2] - memo[l[i] - 2]
end
