n,q = gets.split.map(&:to_i)
s = gets.chomp
l = []
r = []
for i in 1..q do
  l[i], r[i] = gets.split.map(&:to_i)
end

a = [0, 0]
count = 0

for i in 2..n do
  if s[i-1] == "C" && s[i-2] == "A"
    count += 1
  end
  a[i] = count
end

for i in 1..q do
  puts a[r[i]] -a[l[i]]
end
