n, q = io.read("*n", "*n", "*l")
s = io.read()
t = {0}
for i = 2, n do
  if s:sub(i - 1, i - 1) == "A" and s:sub(i, i) == "C" then
    t[i] = t[i - 1] + 1
  else
    t[i] = t[i - 1]
  end
end

for iq = 1, q do
  l, r = io.read("*n", "*n")
  z = t[r]
  if 1 < l then z = z - t[l] end
  print(z)
end
