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