N,Q = gets.chomp.split(" ").map(&:to_i)
S = gets
a = 0
for i in 1..Q do
  l,r = gets.chomp.split(" ").map(&:to_i)
  for j in l-1..r-2 do
    if S[j] == "A" and S[j+1] == "C" then
      a += 1
    else
    end
  end
  puts a
  a = 0
end